State Machine
State Machine
Massimo Felici
State Machines
• State Machines or Statechart Diagrams give us the means to control
decisions
• Each state is like a ‘mode of operation’ for the object the Statechart Diagram
is considering
Suggested Readings
• Objects have behaviours and states. The state of an object depends on its
current activity or condition. A Statechart Diagrams shows the possible states
of the object and the transitions that cause a change in state.
Example 3
State Machines
State Machines
• Simple
• Complex States
– Composite and Submachine States
– Concurrent Substates
– History States
– Synch States
• Transitions
• Synchronisation Bars and Decision Points
• Transition types
• Transitions to/from Composite States
• Actions
Events
• Internal or External Events trigger some activity that changes the state of the
system and of some of its parts
States
• A state is a condition of being at a certain time
• A point in the lifecycle of a model element that satisfies some condition, where
some particular action is being performed or where some event is waited
State Machines
Actions
• States can trigger actions
• Five triggers for actions: On Entry, Do, On Event, On Exit, and Include
• An activity captures complex behaviour that may run for a long duration – An
activity may be interrupted by events, in which case it does not complete
State Machines
• A state called Login
• Composite States can be further broken down into substates (either within the
state or in a separate diagram).
• A composite state is a state with one or more regions.
• A region is simply a container for substates.
• A composite state with two or more regions is called orthogonal.
• A composite state may have an additional compartment called the
decomposition compartment, which is a detailed view of the composite state
showing regions, substates and transitions.
• UML defines a submachine state as a way to encapsulate states and transitions
so that they can be reused.
• A composite state with two or more regions is called orthogonal. Unlike
composite states, submachine states are intended to group states, so you
can reuse them. Composite states are typically specific to the current state
machine.
11
State Machines
State Machines
Transitions
• Viewing a system as a set of states and transitions between states is very useful
for describing complex behaviors
• Understanding state transitions is part of system analysis and design
• A Transition is the movement from one state to another state
• Transitions between states occur as follows:
1. An element is in a source state
2. An event occurs
3. An action is performed
4. The element enters a target state
• Multiple transitions occur either when different events result in a state
terminating or when there are guard conditions on the transitions
• A transition without an event and action is known as automatic transitions
Transitions
Compound Transition - A representation of the change from one complete
state machine configuration to another.
Decision Points
• Let a transition to split along a number of transitions based on a condition
• To the substates
• If the state diagram gets too complex consider splitting it into smaller classes
State Machines
1. Select the power level
3. Press start
4. Safety: the oven should never operate when the door is open
State Machines
Protocol state machines show the bahavior of a protocol. They show how
participants may trigger changes in a protocols state and the corresponding
changes in the system.
Readings
Required Readings
Suggested Readings
Summary
• Statechart Diagrams