23.6. Strategy (GoF)
The next design problem to be resolved is to provide more complex pricing logic, such as a store-wide discount for the day, senior citizen discounts, and so forth.
The pricing strategy (which may also be called a rule, policy, or algorithm) for a sale can vary. During one period it may be 10% off all sales, later it may be $10 off if the sale total is greater than $200, and myriad other variations. How do we design for these varying pricing algorithms?
How to design for varying, but related, algorithms or policies? How to design for the ability to change these algorithms or policies?
Define each algorithm/policy/strategy in a separate class, with a common interface.
Since the behavior of ...