What are the differences between the Strategy design pattern and the State design pattern? I was going through quite a few articles on the web but could not make out the dif
Strategy pattern is used when you have multiple algorithm for a specific task and client decides the actual implementation to be used at runtime.
UML diagram from wiki Strategy pattern article:
Key features:
Refer to this post for more info & real world examples:
Real World Example of the Strategy Pattern
State pattern allows an object to alter its behaviour when its internal state changes
UML diagram from wiki State pattern article:
If we have to change the behavior of an object based on its state, we can have a state variable in the Object and use if-else condition block to perform different actions based on the state. State pattern is used to provide a systematic and lose-coupled way to achieve this through Context and State implementations.
Refer to this journaldev article for more details.
Key differences from sourcemaking and journaldev articles: