State diagram (UML)

from Wikipedia, the free encyclopedia
SysML structure diagrams
Internal block diagram
  Parametric diagram
Package diagram
Block definition diagram
SysML behavior diagrams
Activity diagram
Sequence diagram
State diagram
Use case diagram
Further diagrams of the SysML
Prerequisite Diagram
Structure diagrams of the UML
Class diagram
Component diagram
Composition structure diagram
Object diagram
Package diagram
Profile diagram
Distribution diagram
UML behavioral diagrams
Activity diagram
Use case diagram
Interaction overview diagram
Communication diagram
Sequence diagram
Timing diagram
State diagram

The state diagram ( English state diagram ) is one of the 14 chart types of language UML for software and other systems. It graphically represents a finite automaton in a UML special form and is used to specify either the behavior of a system or the permissible use of the interface of a system.

The diagram form used in UML is a variant of the state transition diagram . In addition to this diagram form, there are other forms in computer science and telecommunications that do not differ fundamentally, but differ in their expressiveness.

Theoretical foundations

The type of state machine shown in UML state diagrams is an object-based variant of Harel state diagrams, which were incorporated and expanded by the UML. UML state machines overcome the limitations of traditional finite machines and receive their greatest advantages. The UML state diagram introduces new concepts of hierarchically nested states and orthogonal areas and expands the concept of action accordingly. UML state machines also have the properties of Mealy and Moore machines. They support actions that depend on the state of the system and a triggering event at the same time, as in Mealy machines , as well as entry and exit actions, which are more state-oriented than action-oriented, as in Moore machines .

description

A state diagram shows the states of a state machine (e.g. an object or a system) that are permitted during runtime and specifies the events that trigger its state transitions. A state diagram describes a hypothetical machine ( finite automaton ) that is in exactly one state of a finite set of states at any point in time.

The states in a state diagram are represented by rectangles with rounded corners (in other diagram forms outside of UML often circles, ellipses or simple rectangles). The arrows between the states symbolize possible state transitions. They are labeled with the events that lead to the respective state transition.

elements

The state machine shown in a diagram consists of nodes ( English vertices ) and (state) transitions ( English transitions ). The transitions connect the source and one target node. Each node is either a state ( English state ) or a so-called pseudo state ( English pseudo state ).

conditions

Representation of states

A state diagram is a graph with states as nodes and state transitions as edges. A state is shown in the diagram as a rectangle with rounded corners and labeled with the name of the state. If an object is in a state, all so-called internal activities that are specified in this state can be carried out on this object. In this case, the representation of the state is divided into two parts. The name of the state can be noted in the upper section of the rectangle. In the lower section u. a. Internal activities are listed, whereby an activity can contain several actions. A state models a situation in which a certain, unchangeable condition applies. Usually this invariant is only given implicitly; if you want to formulate it explicitly, you can assign it to the state as a restriction.

Three behavioral specifications , for example in the form of an activity or an interaction , can be assigned to the state:

  • a behavior that is executed when the state machine enters the state ( entry behavior )
  • a behavior that is executed when the state machine leaves the state ( exit behavior )
  • a behavior that is executed while the state machine is in the state ( doActivity )
  • a behavior that is executed when a certain event occurs. (eng. event behavior )

In contrast to the first three behaviors, the event behavior specifies an actual event in the state (e.g. mouseOver / peep).

A state is usually graphically represented as a rectangle with rounded corners, but slightly different forms of representation are also possible, see examples in the figure on the right.

Transitions

Representation of transitions

A transition connects a source and a destination node. The transition can be assigned a behavior specification that describes the behavior that is executed when the transition is run through. This behavior is effect ( English effect ). A guard expression can protect the transition: the transition can only be passed through if the guard expression is true.

Inner transitions and outer transitions

A distinction is made between inner and outer transitions. Inner transitions describe the reaction to an event that triggers an activity but not a state transition. Since there is no change of state, no entry or exit activities are carried out. Entry and exit activities are modeled in the same notation, but require the keywords entry and exit instead of the name of the triggering event to indicate that the respective activity is executed when the state is entered or exited. Inner transitions are modeled within states. If a state is exited as a reaction to an event and another state is entered, one speaks of an external transition. In the course of the state transition, any exit activities of the source state and entry activities of the target state are carried out. A special outer transition is the self-transition, in which the source state and the target state are identical. The figure shows examples of inner and outer transitions.

History state

History states are used if, after an external transition that leads out of a complex state, you want to find the same sub-state that was active before the transition occurred. The history state remembers which sub-state of a complex state was last active. If a transition from the outside leads to the history state, this activates the "old" sub-state and all entry activities are carried out sequentially from the outside to the inside. A history state can have any number of incoming connections, but only one outgoing connection. The outgoing edge must not have any events or conditions and has the sub-state as its target, which is to become active if the complex state has never been active before and therefore no “last active sub-state” exists, or if the complex state was last regularly via the Was left reaching a final state. There are two types of history states, the shallow history state and the deep history state. Each complex state may only have a maximum of one shallow and one deep history state. The flat history state restores the state that is directly on the same level in the complex state as the flat history state itself. The deep history state, on the other hand, remembers the last active sub-state across the entire nesting depth.

syntax

Event (arguments) [condition] / activity

Pseudo-states

Symbols for pseudo-states

The pseudo state is a control element that influences the sequence of a state machine. In contrast to a real state, there are no value assignments in a pseudo state.

The UML2 knows the following pseudo-states:

  • the start state (engl. initial )

Has no incoming transitions and only one outgoing transition, which indicates the state in which the start is made.

  • the terminator (engl. terminate )

Has no outgoing transitions. The object whose behavior is being modeled ceases to exist.

  • the union (engl. join )

Union of the control flow of several parallel states

  • the fork (engl. fork )

Splitting the control flow into several parallel states

  • the intersection (engl. junction )
  • the decision (engl. Choice )

Node from which several alternative transitions can start.

  • the entry point (engl. Entry Point )
  • the exit point (engl. exit point )

Historical states can store the internal state in a complex state from which the transition (before an interruption) started. At a later point in time, you can return to this state via transitions from higher-level states, with all entry activities being carried out again.

  • the flat history (engl. shallow history )

The flat history state saves one level.

  • the deep history (Engl. deep history )

In the deep history state, all states are saved across the entire nesting depth.

Examples of state diagrams

Behavioral state machine

Example of a behavior state machine

A behavioral state machine models the behavior of a model element. The state machine in the figure on the left specifies, for example, the behavior of a washing machine.

Protocol state machine

Example of a protocol state machine

A protocol state machine ( English protocol state machine ) specifies the permitted use of the behavioral characteristics of a classifier .

In the figure on the left, for example, a web service is specified that can be used to reserve flights. The assigned protocol state machine specifies the order in which the operations of the web service are to be called. The specification shows, for example, that a flight can only be booked if it has been successfully reserved beforehand or that a flight that has been booked can no longer be canceled.

literature

  • Christoph Kecher: UML 2.0 - The comprehensive manual . Galileo Computing, 2006, ISBN 3-89842-738-2 .
  • Heide Balzert: Textbook of Object Modeling - Analysis and Design with UML 2 . Elsevier Spectrum Academic Publishing House, 2005, ISBN 3-8274-1162-9 .
  • David Harel: Statecharts: A Visual Formalism for Complex Systems . In: Science of Computer Programming . tape 8 , 1987, pp. 231–274 ( wisdom.weizmann.ac.il [PDF; 1.9 MB ] written 1984/86).

Individual evidence

  1. Harel, David: Statecharts: A Visual Formalism for Complex Systems (PDF; 1.9 MB) 1987. Accessed March 9, 2011.
  2. a b c Martina Seidl, Marion Brandsteidl, Christian Huemer, Gerti Kappel: UML @ Classroom An introduction to object-oriented modeling (PDF; 393 kB) 2012. Accessed on May 14, 2012.