UXInteract / task_046 /environment /code /promotion.go
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
Raw History Blame Contribute Delete
920 Bytes
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 }