Encapsulate various algorithms
to do more or less the same thing.
Need one of several algorithms dynamically.
The algorithms are exchangeable and vary independently
Configure a class with one of many related classes (behaviors).
Avoid exposing complex and algorithm-specific structures.
Data is transparent to the clients.
Reduce multiple conditional statements.
Provide an alternative to subclassing.
Related patterns include
- State, which can activate several states, whereas a
strategy can only activate one of the algorithms.
- Flyweight, which provides a shared object that can be used
in multiple contexts simultaneously, whereas a strategy focuses on one
context.
- Decorator, which changes the skin of an object, whereas a
strategy changes the guts of an object.
- Composite, which is used to combine with a strategy to
improve efficiency.
|