* Hypothesis:
* You find that you want to design a software with a cashier discount for a store.
* How can we design the best?
* We should consider the expansion of future functions and the discount ratio of some commodities.
*
* How can I get a discount first?
* For example, there are only three types of store customers: ordinary users, platinum users, and diamond users (vvvip may be available in the future)
* Different customer identities have different discounts.
*
* Obviously, writing in a class won't work. PS: A single responsibility
Therefore, we would like to regard each situation as a separate class, but in order to unify their behavior, we also need a public method (which can be implemented using an interface or an abstract class)
This is basically in line with the Policy mode:
Defines a series of algorithms, encapsulates them one by one, and enables them to replace each other. The algorithms in this mode can change independently from the client.
PS: But for this discount system, this is not the best result, because you still need to go to the new object on the client, which is not logical, suppose I am running this program,
If there are already new platinum customers in Main, this client can only use platinum customers' discounts.
If only new diamonds are available, they can only be discounted.
Maybe you think I can use this code ....
PS: Kiss ~, You know that if this program will be handed over to the salesperson in the future, they also need to know the Java language to modify, compile ,,,,!
Maybe you want to add if-ekse in main
PS: Well, this is a good solution, but we still have a better solution-factory approach .... The first few of the big talk design patterns have their solutions. If you are interested, please leave a message to discuss them.
Design Mode-Rule Mode 1