The behavior of objects of a class may be described formally in terms of states and events, using a state machine connected to the class under consideration.
A state machine may be associated with each class of the model
Objects that do not present a very pronounced reactive behavior may be considered always to stay in the same state. In this case, their classes do not possess a state machine.
The formalism selected by UML for representing state machines is inspired from Statecharts4. Statecharts are hierarchical state machines that support the concepts of orthogonality, aggregation and generalization (notions that are defined later on in this chapter).
4Harel, D. 1987. Statecharts : A Visual Formalism for Complex Systems. Science of Computer Programming vol. 8.
A state machine is an abstraction of all possible behaviors, similar to the way class diagrams are abstractions of the static structure. Each object follows the behavior described in the state machine associated to its class and is, at a given moment, in a state that characterizes its dynamic states.
State machines and scenarios are complementary. Scenarios are represented by an inter-object collaboration. The type of inter-object interaction occurring between objects that collaborate within a scenario is determined by the respective states of the various objects. State machines may be used to describe the behavior of groups of objects by associating a state machine to a composite, or even to a use case.
A traffic light goes successively from green to orange, then to red before going back to green, and so on, during its whole operational life:
In general, all traffic lights are either in the red, orange, or green state
It is obviously necessary to synchronize traffic lights that are positioned around the same intersection. This synchronization, which depends on the state of the intersection, may also be described in a state machine that is associated to the intersection class.
© 1997 Editions, Eyrolles, Paris, France . All rights reserved.