You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
569 B
24 lines
569 B
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)
|
|
}
|