Search code examples
umlstate-machinefsm

UML Statemachine - Reuse state


I'm trying to model a state machine which reuses a state in order to reduce complexity. I've got three states: State A, B and X.

My state X can either be entered via a transaction from state A or B.

State X includes multiple substates with lots of complexity and I don't wont to implement it twice.

After the process in state X is completed I need to transition back to back to state A or B based on which one was the previous state.

Is there a elegant way to solve this?


Solution

  • A SubMachine will help you to reuse several time part of your state modelling. But if you want to be able to enter into your state X from A or B and then retun to the previous state, ShallowHistory Would be a good idea.

    In the following state machine, I modeled a SubMachine X referenced by both states X1 and X2. I also wanted to model the fact that state X2 in processed after A or B and then next state if the previous one.

    enter image description here

    Another solution consists in playing with transition guards or events/triggers. You must keep in mind that transitions are triggered when specific events occurs or when its guard is true cf. following screenshot.

    enter image description here