我有以下情况,我有不同类型的销售算法来计算销售价格. FixedSaleStrategy不需要basePrice参数,而所有其他策略实现都需要它.有没有一种避免这种冗余参数的好方法?
public abstract class SalesStrategy { public abstract double GetPrice(double basePrice,double saleAmount); } public class AmountOffSale : SalesStrategy { public override double GetPrice(double basePrice,double salesAmount) { return basePrice - salesAmount; } } public class FixedPriceSale : SalesStrategy { public override double GetPrice(double basePrice,double salesAmount) { return salesAmount; } }