Title: Introduction to State Diagrams State Charts in UML
1Introduction to State Diagrams / State Charts in
UML
- CS320 Fundamentals of Software Engineering
- Slides adapted from Matthias Sand
2State Machines Overview
- Basic State Machine Concepts
- State Diagrams / State Charts and Objects
- Advanced Modeling Concepts
- Wrap Up
3Automata
- A machine whose output behavior is not only a
direct consequence of the current input, but of
some past history of its inputs - Characterized by an internal state which
represents this past experience
4State Machine (Automaton) Diagram
- Graphical rendering of automata behavior
Lamp On
Lamp Off
5Outputs and Actions
- As the automaton changes state it can generate
outputs
6Extended State Machines
- Addition of variables (extended state)
ctr Integer
7A Bit of Theory
- An extended state machine is defined by
- a set of input signals (input alphabet)
- a set of output signals (output alphabet)
- a set of states
- a set of transitions
- triggering signal
- action
- a set of extended state variables
- an initial state designation
- a set of final states (if terminating automaton)
8Basic UML Statechart
top state
State
Initial pseudostate
Trigger
Ready
Transition
/ctr 0
stop
Done
Final state
Action
9What Kind of Behavior?
- In general, state machines are suitable for
describing event-driven, discrete behavior - inappropriate for modeling continuous behavior
10Event-Driven Behavior
- Event a type of observable occurrence
- interactions
- synchronous object operation invocation (call
event) - asynchronous signal reception (signal event)
- occurrence of time instants (time event)
- interval expiry
- calendar/clock time
- change in value of some entity (change event)
- Event Instance an instance of an event (type)
- occurs at a particular time instant and has no
duration
11The Behavior of What?
- In principle, anything that manifests
event-driven behavior - Guarded Sequence Diagrams are used in UML for
modeling continuous behavior - In practice
- the behavior of individual objects
- object interactions
- The dynamic semantics of UML state machines are
currently mainly specified for the case of active
objects
12Basic State Machine Concepts State Diagrams /
Statecharts and Objects Advanced Modeling
Concepts Wrap Up
13Object Behavior
InitializeObject
Handling depends on specific request type
Wait forRequest
HandleRequest
TerminateObject
14Object Behavior and State Machines
15Basic State Machine Concepts Statecharts and
Objects Advanced Modeling Concepts Wrap Up
16State Entry and Exit Actions
- A dynamic assertion mechanism
entry/lamp.on()
exit/lamp.off()
17Order of Actions
- Exit actions prefix transition actions
- Entry action postfix transition actions
Resulting action sequence printf(exiting) pr
intf(to off) lamp.off()
printf(exiting) printf(needless) lamp.off()
18Internal Transitions
- Self-transitions that bypass entry and exit
actions
Internal transition triggered by an off event
off/null
19State (Do) Activities
- Forks a concurrent thread that executes until
- the action completes or
- the state is exited through an outgoing transition
do activity
do/while (true) alarm.ring()
20Guards
- Conditional execution of transitions
- guards (Boolean predicates) must be side-effect
free
21Static Conditional Branching
- Merely a graphical shortcut for convenient
rendering of decision trees
value gt 200 /sell
value lt 100 /reject
(value gt 100) (value lt 200) /sell
22Dynamic Conditional Branching
- Choice pseudostate guards are evaluated at the
instant when the decision point is reached
bid /gain calculatePotentialGain(value)
gain gt 200 /sell
gain lt 100 /reject
(gain gt 100) (gain lt 200) /sell
Dynamic Choice point
23Hierarchical State Machines
- Graduated attack on complexity
- states decomposed into state machines
LampFlashing
24Stub Notation
- Notational shortcut no semantic significance
LampFlashing
flash/
FlashOn
on/
FlashOff
25Group Transitions
Default transition to the initial pseudostate
LampFlashing
Group transition
26Completion Transitions
- Triggered by a completion event
- generated automatically when an immediately
nested state machine terminates
completion transition (no trigger)
27Triggering Rules
- Two or more transitions may have the same event
trigger - innermost transition takes precedence
- event is discarded whether or not it triggers a
transition
LampFlashing
FlashOn
off/
FlashOff