How does Strategy pattern differ from State pattern?
Aspect Strategy Pattern State Pattern
Purpose Encapsulates interchangeable
behaviors (algorithms).
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