Screenshot 2022-11-07 at 12.53.15

Introduction


Every object takes a finite number of different stages during its life. State machine diagrams are used as follows:

  • To model the possible states of a system or object.
  • To show how state transitions occur as a consequence of events.
  • To show what behaviour the system or object exhibits in each state.

For example: high-level description of the behaviour of a lecture hall:

Screenshot 2022-11-07 at 12.55.04

Where occupy() and release() are the transitions and “free = true”/“free = false” are the states.

Another example would be a Digital Clock: Screenshot 2022-11-07 at 12.56.27

States


They are nodes of the state machine:

200

When a state is active:

  • The object is in that state.
  • All internal activities specified in this state can be executed, meaning an activity can consist of multiple actions.

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.

200

Transitions


Syntax

Change from one state to another:

370

  • Event (trigger)

    • Exogenous (has an external cause or origin) stimulus.
    • Can trigger a state transition.
  • Guard (condition)

    • Boolean expression.
    • If the event occurs, the guard is checked.
    • If the guard is true:
      • All activities in the current state are terminated.
      • Any relevant exit activity is executed.
      • The transition takes place.
    • If the guard is false:
      • No state transition takes place, the event is discarded.
  • Activity (effect)

    • Sequence of actions executed during the state transition.

Types

  • Internal:

300

  • External:

300

When do the following transitions take place?

Screenshot 2022-11-07 at 13.12.28

Sequence of Activity Executions

Assuming is active, what is the value of after occurred?

500

  • becomes active, is set to the value 4.
  • occurs, the guard is checked and evaluates to true.
  • is left, is set to 5.
  • The transition takes place, is set to 10.
  • is entered, is set to 11.

Registration status of an exam example:

500

Types of Events


Signal Event

Receipt of a sinal.

  • e.g.: rightmousedown, sendSMS(message).

Call Event

Operation call.

  • e.g.: occupy(user, lectureHall), register(exam).

Time Event

Time-based state transition:

  • Relative: based on the time of the occurrence of the event.
    • e.g.: after(5 seconds).
  • Absolute
    • e.g.: when(time==16:00), when(data==20150101).

Any Receive Event

Occurs when any event occurs that does not trigger another transition from the active state:

  • Keyword all.

Completion Event

Generated automatically when everything to be done in the current state is complete.

Change Event

Permanently checking whether a condition becomes true.

E.g.: when(x > y), after(90min).

Change Event vs Guard


500

500

500

Types of States


Initial State

It is a pseudo-state, meaning it is transient (system cannot remain in that state). It is more of a control structure than a real state.

No incoming edges.

  • If > 1 outgoing edges:

    • 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 (exception: new()).

Final State and Terminate Node

  • Final State

    • Real state.
    • Marks the end of the sequence of state.
    • Object can remain in a final state forever.
    • 25
  • Terminate Node

    • Pseudo-state.
    • Terminates the state machine.
    • The modelled object ceases to exist (= is deleted).
    • 25

Decision Node

It is a pseudo-state and is used to model alternative transitions.

500

Example

500

Parallelisation and Synchronisation Node

  • Parallelisation node

    • Pseudo-state.
    • Splits the control flow into multiple concurrent flows.
    • 1 incoming edge.
    • 1 outgoing edges.

    • 70
  • Synchronisation node

    • Pseudo-state.
    • Merges multiple concurrent flows.
    • 1 incoming edges.

    • 1 outgoing edge.
    • 70

Summary


Screenshot 2022-11-07 at 13.40.00

Screenshot 2022-11-24 at 11.06.15


Part 2 here.