juniorDesign Patterns
What is the Strategy Pattern?
Updated Apr 28, 2026
Short answer
A behavioral pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.
Deep explanation
Strategy extracts behaviors into separate classes. The original object (context) stores a reference to a strategy object and delegates the work to it. This eliminates massive conditional statements and complies with the Open/Closed Principle.
Real-world example
A navigation app offering different routing algorithms (walking, driving, public transit) interchangeable at runtime.
Common mistakes
- Using Strategy when the algorithms rarely change, causing unnecessary class explosion.
Follow-up questions
- How does Strategy differ from State pattern?