Title: State Machines
1State Machines
2The State Diagram can be a powerful design aid,
and one you may not have seen before
State Diagrams illustrate the dynamic behavior of
a systemwhere events trigger actions that cause
the system to changeits state.
3A State Diagram for a light bulb controlled with
a toggle switch
The event flip switch to 1 triggers the action
current flows and the transition to the on
state. The event flip switch to 0 triggers
the action current stops flowingand the
transition to the off state.
4A State Diagram for a light bulb controlled with
a pushbutton switch
The same event (button pressed) triggers
different actions depending upon its current
state.
5Different events may also cause transitions to
the same state
Different events may cause transitions to
different states
However, state transitions must be deterministic
that is, the same eventcannot cause a transition
from one given state to more than one subsequent
state.
6The same event can cause different states to
transition to the same state
These state transitions are still deterministic
since the same eventdoes not cause a transition
from one given state to more than one subsequent
state.
7In a complex system, different events may cause
transitions to different states or to the same
state
8It is common for an event to result in an action,
but no state transition
9Initial and Final states may be indicated as
follows
10A guard may be used to illustrate a condition
that must be satisfied before a state transition
can occur.
The guard appears in brackets ltguardgt
11State Diagrams can be used to help specify the
dynamic logic implemented in Controller objects
in response to events that the Controller receives
12Group Activity Draw the State Transition Diagram
for the iPod Shuffle
- Event sources are
- Power switch
- Pause/Play button
- Next button
- Previous button
- (ignore volume buttons they dont affect state)
- How many different states are there?
- What is the Initial state?
- What is the Final state?
- How many different transitions between states?