2IX20 04 UML State Machine Diagrams
2IX20 04 UML State Machine Diagrams
Jeroen Keiren
3 2IX20 Lecture 4
State machine diagrams
Diagram
Structure Behavior
Diagram Diagram
Class Package Profile Object Activity State Machine Interaction Use Case
Diagram Diagram Diagram Diagram Diagram Diagram Diagram Diagram
4 2IX20 Lecture 4
State machine diagrams
Example
model of H2O:
• States: liquid, gas (vapour), solid (ice)
• Transitions: melting, freezing, vaporization, condensation
5 2IX20 Lecture 4
Example: Lecture Hall with Details
class LectureHall {
private boolean free;
6 2IX20 Lecture 4
Background: hierarchical state diagrams
David Harel
Weizmann Institute of Science, Israel
7 2IX20 Lecture 4
States and transitions
• States
• Transitions
• Guards
• Events
• Activities
8 2IX20 Lecture 4
State
• entry / Activity(...)
• Executed when object enters state
• exit / Activity(...)
• Executed when object exits state
• do / Activity(...)
• Executed while object remains in state
9 2IX20 State machine diagrams: states and transitions
Transition
• Event (trigger)
• Exogenous stimulus
• Can trigger state transition
• Activity (effect)
• Sequence of actions executed during state transition
• Guard (condition)
• Boolean expression
• If event occurs, guard is checked
• If guard is true
• All activities in current state are terminated
• Any relevant exit activity is executed
• Transition takes place
• If guard is false
• No state transition takes place, event is discarded
Signal event
• Receipt of signal, e.g., rightmousedown, sendSMS(message)
Call event
• Operation call, e.g., occupy(user,lectureHall), register(exam)
Time event
• Time-based state transition
• Relative: based on time of occurrence of event, e.g., after(5 seconds)
• Absolute, e.g, when(time==16:00), when(date==20150101)
• Initial state
• Final state
• Terminal node
• Decision node
• Parallelization
26 2IX20 Lecture 4
Initial State
Final State
• Real state
• Marks end of sequence of states
• Object can remain in final state forever
Terminate Node
• Pseudostate
• Terminates state machine
• Modeled object ceases to exist (= is deleted)
• Pseudostate
• Used to model alternative transitions
equivalent?
• Pseudostate
• Used to model alternative transitions
equivalent?
• Pseudostate
• Used to model alternative transitions
equivalent?
=
equivalent?
• Pseudostate
• Used to model alternative transitions
equivalent?
=
equivalent?
≠
32 2IX20 State machine diagrams: types of states
Example: Decision Node
Parallelization node
• Pseudostate
• Splits control flow into multiple concurrent flows
• 1 incoming edge
• >1 outgoing edges
Synchronization node
• Pseudostate
• Merges multiple concurrent flows
• >1 incoming edges
• 1 outgoing edge
34 2IX20 State machine diagrams: types of states
Entry and Exit Points
Encapsulation mechanism
• Composite state shall be entered or exited via a state other than the initial and final states
• External transition must/need not know structure of composite state
External view
39 2IX20 Lecture 4
Composite State
Substates
• Composite state divided into two or more regions separated by dashed line
• One state of each region is active at any point in time: concurrent substates
• Entry: transition to boundary of orthogonal state activates initial states of all
regions
• Exit: final state must be reached in all regions to trigger completion event
Refinement symbol
(optional)
• Deep history state restores last active substate over the entire nesting depth
Event Config
„Beginning“ { S5 }
e1 { S4,S1,S1.1 }
e2 { S4,S1,S1.2 }
e10 { S5 }
e9 (H→) {S4, S1,S1.1}
Event Config.
„Beginning“ { S5 }
e1 { S4,S1,S1.1 }
e2 { S4,S1,S1.2 }
e10 { S5 }
e8 (H*→) { S4,S1,S1.2 }
Event Config.
„Beginning“ { S5 }
e9 (H→) { S4,S1,S1.1}
Event Config.
„Beginning“ { S5 }
e8 (H*→) { S4,S3,S3.1 }