File size: 920 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package promotion

type Order struct {
    OriginalAmount float64
    UserLevel      string
    Category       string
}

type Strategy interface {
    Discount(order Order) float64
}

type PromotionCalculator struct {
    strategies []Strategy
}

func NewPromotionCalculator(strategies ...Strategy) *PromotionCalculator {
    return &PromotionCalculator{strategies: strategies}
}

func (p *PromotionCalculator) FinalAmount(order Order) float64 {
    // TODO: implement by summing discounts from original amount.
    return order.OriginalAmount
}

type FullReductionStrategy struct{}
func (FullReductionStrategy) Discount(order Order) float64 { return 0 }

type UserLevelDiscountStrategy struct{}
func (UserLevelDiscountStrategy) Discount(order Order) float64 { return 0 }

type CategoryDiscountStrategy struct{}
func (CategoryDiscountStrategy) Discount(order Order) float64 { return 0 }