Strategy Design Pattern
Problem
How can we gain the ability to use different algorithms for like functionality, having the clients contain the code that implements the algorithms? How can we facilitate the extensibility of an algorithm set? How can we use different algorithms without complex conditionals?
Solution
The answer is the strategy. A strategy is a collation of algorithyms each implemented in its own concrete subclass. All the algorithms implement the same result, but may do so differently. Thus a separate class can access the functionality without having to contain it internally.
Consequences
Can implement a range of algorithms each encapsulated and easy to modify.
This provides a way to implement similar functionality without having to subclass the general class, only the algorithm.
One problem is that in order to determine which algorithm to use, the context class must know something about each algorithm.
Strategies increase the number of object in a system, but this can be alleviated by sharing the algorithm classes.