Discuss / Java / 使用策略模式新增一种策略,允许在满100减20的基础上对Prime会员再打七折。

使用策略模式新增一种策略,允许在满100减20的基础上对Prime会员再打七折。

Topic source

Dominga丶

#1 Created at ... [Delete] [Delete and Lock User]
public class OverAndPrime implements DiscountStrategy{    @Override    public BigDecimal getDiscount(BigDecimal total) {        return  new PrimeDiscountStrategy().getDiscount(total.subtract(new OverDiscountStrategy().getDiscount(total))).add(new OverDiscountStrategy().getDiscount(total));    }}

Dominga丶

#2 Created at ... [Delete] [Delete and Lock User]

public class OverAndPrime implements DiscountStrategy{

@Override
public BigDecimal getDiscount(BigDecimal total) {

return new PrimeDiscountStrategy().getDiscount(total.subtract(new OverDiscountStrategy().getDiscount(total))).add(new OverDiscountStrategy().getDiscount(total));

}
}


  • 1

Reply