设计模式 strategy_test 实现

2022-07-21 浏览 (1201)

golang 设计模式 strategy_test 代码实现

package strategy

func ExamplePayByCash() {
	payment := NewPayment("Ada", "", 123, &Cash{})
	payment.Pay()
	/ Output:
	/ Pay $123 to Ada by cash
}

func ExamplePayByBank() {
	payment := NewPayment("Bob", "0002", 888, &Bank{})
	payment.Pay()
	/ Output:
	/ Pay $888 to Bob by bank account 0002
}

目录

go 设计模式

相关文章

策略模式

设计模式 strategy 实现

^