Beatles1692
Beatles1692

Reputation: 5330

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:

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:

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.

Upvotes: 2

Views: 1027

Answers (2)

MechaRyRy
MechaRyRy

Reputation: 133

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

Upvotes: 0

Wilhelm Medetz
Wilhelm Medetz

Reputation: 621

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.

Upvotes: 1

Related Questions