How to use state pattern correctly?

后端 未结 9 780
既然无缘
既然无缘 2021-01-29 21:54

I\'ve encountered a few implementations of state pattern in my programming experience, and done a few. I\'ve seen them used in various scenarios (mostly UI and parsing). The tro

9条回答
  •  旧时难觅i
    2021-01-29 21:59

    Most of the times, the states in a state pattern design are handling more that one state (or substates of the state) which makes them harder to maintain.

    If a state has any kind of selection in there, its mostly handling more than one state.

    I takes a lot of discipline to keep the states clean.

    A possible solution to this is to make more complex states statemachines themselves (HSM). This makes it a lot more readable at the upper level because it has to deal with fewer states.

提交回复
热议问题