Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java销售类场景中的实现选择_Java_Design Patterns_Uml - Fatal编程技术网

Java销售类场景中的实现选择

Java销售类场景中的实现选择,java,design-patterns,uml,Java,Design Patterns,Uml,销售应用场景: 此应用程序根据各种策略向客户提供折扣: 例如: customer total purchase amount is > 10000 - discount calculation following Rule1 customer is a senior citizen - discount calculation following Rule2 customer is purchasing on Tuesday - discount calculation follo

销售应用场景:

此应用程序根据各种策略向客户提供折扣:

例如:

customer total purchase amount is > 10000  -  discount calculation following Rule1

customer is a senior citizen - discount calculation following Rule2

customer is purchasing on Tuesday - discount calculation following Rule3

customer is purchasing on 1st of everymonth- discount calculation following Rule4

customer is purchasing on a  specific day (admin can provide this offer)- discount calculation following RuleX
如果一位老年人在周二购买的金额超过10000英镑,那么理想情况下,他应该这样做 从上述场景中获得最合适的折扣。我们可以使用什么设计模式来解决这个问题? 这里可以使用策略模式吗?(这里我们需要使用多个基于规则的计算来决定 其中一个应该最适合用户,但策略支持在运行时选择singleImplementation(diccount计算)


您需要为此设计模式吗?就我而言,我只需测试客户对所有优惠的资格,并比较通过测试的所有优惠的折扣


有些产品可能总是比其他产品更有趣,如果是这样的话,您可以在其他产品之前对其进行测试,以便在客户有资格获得此类产品时为您节省一些测试。

根本不需要设计模式。 你需要的是一个图表,它涵盖了你所有的不同情况。最后,您必须实现这些流案例


供参考: 如果您需要针对特定抽象类型的不同实现,则可以应用策略模式。例如,请查看
java.util.List
的具体实现,这些实现是作为策略模式实现的

您不应该在场景中使用策略模式的原因是,您的销售应用程序中永远不会有有限数量的不同实现。很快或稍后,这将以一个无法维护的战略怪物结束