Intent

Group several algorithms in a single module to provide alternatives. Also known as policy.

Where to use & benefits

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


Source Code Links