What is the difference between Strategy design pattern and State design pattern?

前端 未结 19 1652
太阳男子
太阳男子 2020-12-02 04:06

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

相关标签:
19条回答
  • 2020-12-02 04:41

    In layman's language,

    in Strategy pattern, there are no states or all of them have same state. All one have is different ways of performing a task, like different doctors treat same disease of same patient with same state in different ways.

    In state Pattern, subjectively there are states, like patient's current state(say high temperature or low temp), based on which next course of action(medicine prescription) will be decided.And one state can lead to other state, so there is state to state dependency( composition technically).

    If we technically try to understand it , based on code comparison of both, we might lose the subjectivity of situation,because both look very similar.

    0 讨论(0)
提交回复
热议问题