4. State Machine Diagram

4.1. Procedure & Checklist

Brainstorming

Create a table with the following columns:

  • 1st column: All states,

  • 2nd column: All events that can occur internally or externally,

  • 3rd column: All processing steps that must be listed.

Which states does the automat receive?

  • The starting point is the initial state.

  • By which events is a state left?

  • Which subsequent states occur?

  • By what is the state defined (attribute values, object relations)?

Does the state machine need a final state?

  • If the final state is reached, the processing of the state machine ends.

  • If the state machine describes a life cycle, the termination of the state machine can be equated with the end of life of the object.

  • No processing may be performed in a final state; it may not have any output arrows.

Which activities are to be modeled?

  • Is there any processing associated with a state diagram?

  • Do all incoming transitions of a state have the same activity? –> entry activity

  • Do all outgoing transitions of a state possess the same activity? –> exit activity

  • Is the processing linked to the duration of the state? –> do-activity

Which events are to be modeled?

  • External events from the user or from other objects;

  • Temporal events (duration, time);

  • Internally generated events of the class or use case.

Analytical steps - Appropriate state name.

  • Describes a specific time period.

  • Does not contain a verb.

Analytical steps - Are all transitions correctly entered?

  • Is every state reachable?

  • Can each state - except the final state - be exited?

  • Are the events of the transition unique?

  • Can events occur that are not covered by the specified events?

Source: “UML 2 compact with checklists”, Heide Balzert

4.2. Further

Hint

State diagrams can be created online on draw.io (https://app.diagrams.net/).

Note

In the literature there are different uses of the “entry”, “do” and “exit” conditions. We use the following notatin:

  • Entry activity: action which is triggered when entering the state, e.g. light = False

  • Do activity: action which is executed as long as you are in this state, e.g. count sheep

  • Exit activity: action which is executed when one leaves the state, e.g. sleep = True

https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-state-machine-diagram/

4.3. Examples for state diagrams

Example for the circuit of a person traffic light

../../_images/StateMachineDiagram1.png
../../_images/StateMachineDiagram2.png