Intent
Group several algorithms in a single module to provide alternatives. Also known as policy.
Where to use & benefits
- 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.
Structure

Participants
Strategy (IShapeDrawer)
declares an interface common to all supported algorithms. Context uses this interface to call the algorithm defined by a ConcreteStrategy
ConcreteStrategy> (ShapeGraphicsDrawer)
implements the algorithm using the Strategy interface
Context (ShapeDrawCommands)
is configured with a ConcreteStrategy object and maintains a reference to a Strategy object
Example
In the demonstration application, the strategy pattern is used to vary the strategy in drawing the shape by interpreting the command object which encapsulates the shape object information. Here, only one strategy (ShapeGraphicsDrawer) is used, but one can implement different strategy to perform the same.
Class Diagram
