The link between the operations defined in the class specification and the events that appear in statechart diagrams is performed using actions and activities.
Each transition may be labeled with the name of an action to execute when the transition is triggered by an event. To respect the general semantics of the transition, the action is considered as instantaneous and atomic.
When a transition is triggered, the action that is attached to it is executed instantly.
The action corresponds to one of the operations declared in the class of the object that is to receive the event. The action has access to the event's parameters, as well as the object's attributes. In reality, every operation takes some time to execute, so the concept of an instantaneous action must be interpreted as an operation with a negligible execution time compared to the system's dynamics.
States may also contain actions; these are executed upon entering or exiting a state, or when an event occurs while the object is the state.
An action may be executed upon entering or exiting the state, or upon occurrence of an event within the state.
The action on entry (which is symbolized by the keyword
) is executed in an instantaneous and atomic way upon entry into the state. Similarly, the action on exit (symbolized by entry /
) is executed upon exiting the state. The action on an internal event (symbolized by the event name followed by exit /
) is executed upon the occurrence of an event that does not lead to another state. An internal event does not trigger the execution of the input and output actions, unlike the triggering of a self-transition./
Actions correspond to operations with a negligible execution time. An operation that takes time corresponds to a state more than to an action. The keyword
indicates an activity — an operation that takes a non-negligible time, and that is executed while the object is in a given state.do /
In contrast to actions, activities may be interrupted at any moment, immediately a state exit transition is triggered. Some activities are cyclic and only stop when an exit transition is triggered. Other activities are sequential and start when the state is entered (immediately after the execution of the entry actions). When a sequential activity reaches its end, it is possible to leave the state if one of the transitions can be traversed. This type of transition is not triggered by an event and is called automatic transition.
When the activity ends, the automatic transitions — without events, but possibly protected by guards — are triggered.
States may also contain variables expressed as attributes. State variables belong to the class associated to the state machine, but may be shown in the statechart diagrams when they are manipulated by actions or activities.
© 1997 Editions, Eyrolles, Paris, France . All rights reserved.