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

Diagram

Strategy

Participants

Strategy
  • Declares an interface common to all supported algorithms
  • Context uses this interface to call the algorithm defined by a ConcreteStrategy
ConcreteStrategy
  • Implements the algorithm using the Strategy interface
Context
  • Is configured with a ConcreteStrategy object
  • Maintains a reference to a Strategy object
  • May define an interface that lets Strategy access its data.
Resources URL: 
notes/design_patterns/resources
Sources URL: 
notes/design_patterns/sources

See Also