Java – Design of multi-level and hierarchical state machines

In network programming, you need a state machine with multiple levels of depth

State Machine 1
     State Machine 2

     State Machine 3
          State Machine 4

Here, state machine 1 contains two state machines 2 and 3 3 also includes the machine 4

According to the state of the external machine, the message should pass through the internal state machine In addition, if there are some errors in the internal state machine, the feedback shall be given to the upper computer

Is there a good way to do this?

Now I have an IF statement and a banner of the jungle for me to do so I have been faced with some problems, that is, because the whole state of the state machine is in an unrecoverable state, a flag is not set

Update: I try to keep the state and the machine stationary When the request will pass through the machine and state, the request itself will store all the metadata required In this case, normal state machine mode is not helpful

Solution

State pattern separates state and context Context can store a hierarchy of states that the state subclass itself does not know All if statements disappear because each part under if enters a separate state subclass

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>