Chapter 1

Chapter 29
UML State Diagrams
Basics
Telephone
initial state
off hook
Idle
Active
on hook
transition
event
state
initial state
off hook
Idle
Active
state
on hook
transition
event
• Shows lifecycle of an object
• Event: Significant occurrence
– Example: Phone receiver taken off the hook
– Example: User moves to next level
• State: Condition of an object (or group of objects) at a
moment in time
• Transition: A relationship between states
– One transition: Object moves from one state to the other when a
particular event occurs
How to apply state machine diagrams?
• Object state independent:
– Response to a given event always the same
• Object state dependent:
– Based on state, object may respond differently
to different events
– Example: Ball hits gizmo
• “state = quiet”  Response: Gizmo blinks
• “state = sound on”  Response: Game makes
sound
• Use state machines for state-dependent
objects with complex behavior
When to use state machine diagrams?
• Typically not useful in business information
systems
• More useful in “time varying systems”
– Process control
– Device control
– Protocol handlers
– Games
– Telecommunications programs
How are state machines used?
• To model the behavior of a complex
reactive machine (e.g. gizmo) in response
to events
– Example: Navigation between web pages in a
site
– Example: Event handling based on mode or
conditions (e.g. Edit-Paste button active only if
clipboard has stuff in it)
• To model legal sequence of operations
– Example: Protocol or language specifications
More state diagram notation
transition action
off hook / play dial tone
Idle
[valid subscriber]
on hook
guard condition
Active
Nested (hierarchical states)
off hook / play dial tone
Active
[valid subscriber]
Idle
PlayingDialTone
Talking
on h
ook
digit
digit
connected
complete
Dialing
Connecting
UI Navigation Example
NextGen State Machine Example
Process Sale
WatingForSale
makeNewSale
EnteringItems
endSale
authorized
makeCashPayment
WaitingForPayment
makeCreditPayment
AuthorizingPayment
makeCheckPayment
enterItem