Strategy
Usage
- Also known as: Policy
- Encapsulates an algorithm inside a class
- Define a family of algorithms, encapsulate each one, and make them interchangeable
- Let the algorithm vary independently from clients that use it
Participants
Strategy
ConcreteStrategy
- Declares an interface common to all supported algorithms
- Context uses this interface to call the algorithm defined by a ConcreteStrategy
Context
- Implements the algorithm using the Strategy interface
- Is configured with a ConcreteStrategy object
- Maintains a reference to a Strategy object
- May define an interface that lets Strategy access its data.
