You are on page 1of 2

16 Statecharts and UML State Machine Diagrams

Statecharts, and their UML version, state machine diagrams, are another widely used technique for
modeling the behaviour of a systems. They have a well-understood theoretical foundation, namely finite
automata and their extensions, finite state transducers, in particular Mealy & Moore automata. State
machine diagrams allow to explicitly model how a system reacts to external or internal events, including
temporal events. When a legal event is received, a transition is triggered, as well as optionally an action.
This kind of modeling is particularly well suited for designing (process, device) control systems, (network)
protocols, graphical user interfaces, or computer games; that is, systems where processing of an event
depends on the current state of an object as opposed to systems, where objects always react in the same
way to an event, which is usually the case in business type applications. In this lecture, we introduce
the UML notation for state machine diagrams, discuss how to find relevant states and events, how to
map use cases to state machines, and how to structure complex systems with hierarchical and parallel
decomposition. Additionally, we will briefly look at QA for state machines and discuss their possible
design and implementation, in particular the State design pattern. 16.1

Learning Objectives
Learning Objective 1:
Understand the UML state machine diagram notation
Understand how to model states, events, transitions, and actions
Learn how to model systems with state machine diagrams
Understand how to identify relevant states and events
Learn how to structure diagrams with sequential and parallel decomposition
Learn how to map use cases toe state machines
Understand for what type of systems you should use state machine modeling

Learning Objective 2:
Learn some guidelines for quality assurance on state machines
Understand state machine properties such as state reachability, safety, and liveness

Learning Objective 3:
Understand how to derive design & implementation options for state machine models
Understand the State design pattern

Notes and Further Reading


UML state machine diagrams for requirements engineering are described in [8, Chapter 13.2]. Larman also
provides a good introduction [6, Chapter 29]. One implementation option for state machines is the State
design pattern; An example for this pattern is shown in [6, Chapter 37.16]. For more details on the State
pattern, the original reference [3], as well as the introductory pattern book [2] are recommended reading.
The UML guide also briefly discusses state machine diagrams and their implementation [1, Chapter 10].
For an introduction covering the theoretical background from finite automata over statecharts to UML state
machine diagrams, read Pohls textbook [7, Chapter 14.3.114.3.5]. For even more details on behavioural
modeling, more examples on statecharts and state machines, a description of other techniques like Petri
nets, as well as a comparison between them, consult Jorgensens book [5].

16-1
16-2 Bibliography

Reading Material
Required
[8, Chapter 13.2]

Supplemental
[6, Chapter 29] (Modeling with State Machine Diagrams)
[6, Chapter 37.16] (Example for the State design pattern)
[1, Chapter 10] (UML State Machine Diagrams)
[4] (UML Quick Reference)
[7, Chapter 14.3.114.3.5] (Finite Automata, Statecharts, UML State Machines)
16.52

Bibliography
[1] Martin Fowler. UML Distilled: A Brief Guide to the Standard Object Modeling Language. Addison-
Wesley, 3rd edition, 2004.
[2] E. Freeman, E. Freeman, B. Bates, and K. Sierra. Head First Design Patterns. OReilly & Associates,
Inc., 2004.
[3] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-
Oriented Software. Addison-Wesley, 1995.
[4] Allen Holub. UML Quick Reference. http://www.holub.com/goodies/uml/.
[5] Paul C. Jorgensen. Modeling Software Behavior: A Craftsmans Approach. Auerbach Publications,
2009.
[6] Craig Larman. Applying UML and Patterns. Prentice Hall, third edition, 2005.
[7] Klaus Pohl. Requirements Engineering: Fundamentals, Principles, and Techniques. Springer-Verlag
Berlin Heidelberg, 2010.
[8] Axel van Lamsweerde. Requirements Engineering: From System Goals to UML Models to Software
Specifications. John Wiley & Sons, 2009.

Study Questions
1. Explain the concepts state, event, transition, and action.
2. Describe how you would map multiple use cases involving the same (single) object to one state
machine diagram.
3. What are the differences between the nodes in state machine diagrams and activity diagrams?
4. What about the transitions between nodes in activity and state machine diagrams, is there a difference
as well?
5. Give concrete examples of applications that are (a) well suited for state machine modeling and (b)
not suited for state machine modeling. Explain.
6. Explain the difference between necessary and sufficient conditions for transition firing based on
events and guard conditions.
7. Discuss when you would enhance a specification with (a) sequence diagrams; (b) activity diagrams;
and (c) state machine diagrams, considering boundary conditions such as (1) the number of collabo-
rating objects; (2) the number of scenarios (extensions and alternate flows); and (3) the complexity
of the interactions between agents and system.
8. Name some quality assurance guidelines for state machines.
9. Discuss design and implementation choices for state machine diagrams.
10. Create a simple state machine diagram and create a corresponding UML design class diagram (DCD)
using the State design pattern.
11. Can you transform a state machine diagram with parallel states into an equivalent one with only
sequential states? What would be the consequences (e.g., size of the diagram, complexity)?

SOEN 6481 Lecture Notes, Winter 2015/16

You might also like