package strategy import "designpatterns/factory" type CashFactoryStrategyContext struct { d int cashFactoryStrategy factory.Casher } func (c *CashFactoryStrategyContext) GetCash() { switch c.d { case 1: c.cashFactoryStrategy = &factory.CashNormal{} case 2: c.cashFactoryStrategy = &factory.CashRebate{MoneyRebate: 0.8} case 3: c.cashFactoryStrategy = &factory.CashReturn{MoneyReturn: 5, MoneyCondition: 100} } } func (c *CashFactoryStrategyContext) GetResult(money float64) float64 { return c.cashFactoryStrategy.AcceptCash(money) }