简体   繁体   中英

Having a state machine as a guard of another state machine

I am designing a system that simulates the flow of a document in an organization. For the sake of simplicity let's assume that the flow has the following states:

  • Opened
  • Evaluated
  • Rejected
  • Accepted

There are times that some external resources are required to be available to proceed. Thus if a resource isn't available the whole flow should be put on hold. I imagine that there's another (somehow) parallel state machine that has two states:

  • In Progress
  • On Hold

The way that I thought I could solve this problem was to check the state of the second state machine as a guard condition in every transition of the first state machine. But I wonder if there's a common way or pattern for solving this kind of problem?

BTW, I want to implement this state machines using the Stateless or bbv Common(Appccelerate) libraries.

With a UML state machine you could use hierarchical states together with a history states.

  • In Progress
    • Opened
    • Evaluated
    • Rejected
    • Accepted
    • (H) History state
  • On Hold

Events for the substates of 'In Progress' will only be handled, if 'In Progress' and one of it's substates is active.

The (H) history state can be used to reactivate the most recently active substate when 'In Progress' becomes active.

Based on my experience with state machines I think you would be better off with just the one state machine. Make the On Hold a state and have the other states check in their check conditions whether the desired external resource is available, if it isn't then move the document to the On Hold state.

As for the in progress state, I think this is implied by the other states and not really necessary.

States made up of:

  • CheckConditions, this is where you put your guard conditions
  • ExitConditions
  • EntryConditions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM