What is the difference between a state machine and the implementation of the state pattern?

前端 未结 6 1063
無奈伤痛
無奈伤痛 2020-12-24 05:41

I wonder if a state machine is just the state pattern at work or if there is actually a difference between those two?

I found this article with the

6条回答
  •  遥遥无期
    2020-12-24 06:26

    I wrote an article about the state design pattern and state machines: https://medium.com/@1gravityllc/the-super-state-design-pattern-166127ce7c9a. In the article I'm showing that their focus is different but that they are also not mutually exclusive. There's a way to combine the two to come up with a super state design pattern.

    The emphasis of the state design pattern is on encapsulation of behavior to create reusable, maintainable components (the states).

    The focus of the finite state machine is on states and their transitions (captured by the state diagram) but not on the actual behavior (that’s an implementation detail).

    The article describes how these two concepts can be combined by using a finite state machine to describe and manage the states and their transitions for an object that delegates behavior to state objects using the state design pattern.

提交回复
热议问题