可用于以下方法的最合适的模式是什么。我倾向于 switch 语句的策略模式,但 if 的情况如何。另外,如果我有不同类型的折扣,我也应该使用策略模式怎么办?
public void AddOrder(PaymentType paymentType, OrderType orderType)
{
if (orderType == OrderType.Sale)
{
switch (paymentType)
{
case PaymentType.Cash:
// Do cash calculations here
break;
case PaymentType.CreditCard:
// Do credit card calculations here
break;
}
}
else if (orderType == OrderType.Refund)
{
switch (paymentType)
{
case PaymentType.Cash:
// Do cash calculations here
break;
case PaymentType.CreditCard:
// Do credit card calculations here
break;
}
}
}
谢谢