Stack Explorer

Strategy Pattern

behavioral

Define a family of interchangeable algorithms

Type: pattern

Principles

Common interface for strategiesContext delegates to strategyInterchangeable strategies

When to use

Multiple algorithms for the same task, variable behavior at runtime

When not to use

Single algorithm, unlikely variation

Pros and Cons

Ventajas

  • + Interchangeable algorithms
  • + Avoids conditionals
  • + Easy to add new ones

Desventajas

  • - More classes
  • - Client must know strategies

Related Technologies