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

前端 未结 19 1845
太阳男子
太阳男子 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:24

    State comes with a little bit dependencies within the state derived classes: like one state knows about other states coming after it. For example, Summer comes after winter for any season state, or Delivery state after the Deposit state for shopping.

    On the other hand, Strategy has no dependencies like these. Here, any kind of state can be initialized based on the program/product type.

提交回复
热议问题