LLDbeginner
Strategy Pattern
Strategy encapsulates interchangeable algorithms behind a common interface so behavior can change without rewriting calling code. It is one of the most practical behavioral patterns in interviews.
Reading time
9 min
strategypatternsbehavioralpolicies
What Strategy Solves
If behavior varies by mode, provider, or policy, strategy lets you swap implementations cleanly at runtime.
Examples
- Pricing strategies
- Payment processors
- Retry policies
- Routing or ranking algorithms
Benefits
- Replaces large conditional blocks
- Easier testing
- Better adherence to open/closed principle
Interview Tip
If your design contains a giant switch based on type, strategy is usually worth mentioning.