Strategy Pattern
behavioralDefine a family of interchangeable algorithms
Type: patternPrinciples
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