A state machine diagram is used to:

  • Model the possible states of a system or object
  • Show how the state transitions occur as a consequence of events
  • Show what behaviour the system or object exhibits in each state

There are multiple components to a state machine diagram:

  • State (UML State Machine)

    State is the nodes of the state diagram.

    • When a state is active, the object is in that state.
    • All internal activities specified in the current state can be executed.
    • An activity can consist of multiple actions.

    Activity specifications:

    • entry / Activity(...): executed when the object enters the state
    • exit / Activity(...): executed when the object exits the state
    • do / Activity(...): executed while the object remains in this state

    Link to original
  • Transition (UML State Machine)

    A transition changes from one state to another.

    The syntax used is as follows:

    1. Event (trigger): exogenous stimulus, can trigger state transition
    2. Guard (condition): boolean expression
      • if the event occurs, guard is checked
      • if guard is true:
        • any activities in current state are terminated
        • relevant exit activity is executed
        • transition takes place
      • if guard is false:
        • no state transition takes place, event is discarded
    3. Activity (effect): sequence of actions executed during the state transition

    There are two types of transition:

    Link to original
  • Event (UML State Machine)

    There are different types of events we need to handle in a state diagram:

    • Signal event: receipt of a signal e.g. rightmousedown, sendSMS(message)

    • Call event: operation call e.g. occupy(user, lectureHall), register(exam)

    • Time event: time-based state transition e.g. after(5 seconds) or when(time==16:00)

    • Any receive event: occurs when any event occurs that does not trigger another transition from the active state e.g. keyword = all

    • Completion event: generated automatically when everything to be done in the current state is completed

    • Change event: permanently checking whether a condition becomes true e.g. when(x,y), after(90min)

      Below is a comparison between a change event and a guard:

    Link to original
  • Initial State (UML State Machine)

    The initial state is the start of a state machine diagram.

    • It is a pseudo-state.
    • No incoming edges.
    • If there is more than 1 outgoing edge, guards must be mutually exclusive and cover all possible cases to ensure that exactly one target state is reached.
    • If initial state becomes active, the object immediately switches to the next state.
    • No events allowed on the outgoing edges.

    Link to original
  • Final State (UML State Machine)

    The final state is a real state and marks the end of the sequence of states. Object can remain in a final state forever.

    Link to original
  • Terminate Node (UML State Machine)

    The terminate node is a pseudo-state that terminates the state machine. The modelled object ceases to exist.

    Link to original
  • Decision Node (UML State Machine)

    A decision node is a pseudo-state and is used to model alternative transitions.

    Link to original
  • Parallelisation Node (UML State Machine)

    A parallelisation node is a pseudo-state that splits control flow into multiple concurrent flows. There is one incoming edge and one or more outgoing.

    Link to original
  • Synchronisation Node (UML State Machine)

    A synchronisation node is a pseudo-state that merges multiple concurrent flows. There is one or more incoming edge and one outgoing edge.

    Link to original