How does Strategy pattern differ from State pattern?
Short answer: Aspect Strategy Pattern State Pattern Purpose Encapsulates interchangeable behaviors (algorithms).
Explain a bit more
Encapsulates states and transitions between them. Client Control Client decides which strategy to use. Object changes its own state internally. Behavior Switch Switched externally (e.g., passed as a parameter). Switched internally (e.g., via method call). Example Payment method selection. Document lifecycle (Draft → Published → Archived). Repository Design Pattern
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png