0% found this document useful (0 votes)
21 views89 pages

2IX20 04 UML State Machine Diagrams

The document discusses state machine diagrams in UML. It provides an example of modeling the states of a lecture hall using a state machine diagram with states for free and occupied. It also discusses the key components of state machine diagrams, including states, transitions, events, guards, and activities. Transitions can be triggered by events and can include guards and activities. The ordering of activities during state transitions is also covered.

Uploaded by

Anas Assoufi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views89 pages

2IX20 04 UML State Machine Diagrams

The document discusses state machine diagrams in UML. It provides an example of modeling the states of a lecture hall using a state machine diagram with states for free and occupied. It also discusses the key components of state machine diagrams, including states, transitions, events, guards, and activities. Transitions can be triggered by events and can include guards and activities. The ordering of activities during state transitions is also covered.

Uploaded by

Anas Assoufi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

2IX20 Software Specification

STATE MACHINE DIAGRAMS

Based on the slides provided by M.Seidl,


M.Scholz, C. Huemer and G.Kappel,
authors of the book UML@Classroom
Under the Creative Commons Attribution-
NonCommercial 4.0 International licence.
See http://www.uml.ac.at/en/lernen.

Jeroen Keiren

Mathematics & Computer Science / Formal System Analysis


Bug: Patriot missile failure

• Gulf war, 1991


• Miscalculation is Patriot missile system’s software
resulted in innacurate tracking of incoming
missiles. 28 Dead.
• System clock records time in 10’s of a second.
Multiplied by 10 to calculate second using 24-bit
fixed point register.
• Small chopping error at 24-bit led to significant ken H from Yokohama, Kanagawa-ken,
error. After 100 hours +/- 0.34 seconds Japan (cc BY-SA-2.0)

• Value used to determine where to look for object


See also: https://www-users.cse.umn.edu/~arnold/disasters/patriot.html, https://www.gao.gov/products/imtec-92-26

2 2IX20 Lecture 4 Shared by Dwijesh Kurada


Behavioral modelling

Behavior: the way in which something functions or operates.


- Merriam-Webster

Behavioral modelling: discover key operations in problem domain and build


behavioral models for those operations

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

Deployment Composition Component Sequence Communication Interaction Timing


Diagram Structure Diagram Diagram Diagram Overview Diagram
Diagram Diagram

4 2IX20 Lecture 4
State machine diagrams

• State machine diagrams are a way of modelling behavior in UML


• Every object takes finite number of different states during its life
• State machine diagram used to:
• model possible states of system or object
• show how state transitions occur as consequence of events
• show what behavior system or object exhibits in each state

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;

public void occupy() {


free=false;
}
public void release() {
free=true;
}
}

6 2IX20 Lecture 4
Background: hierarchical state diagrams

• The number of states in a diagram can easily become large


• Make the diagrams more compact: introduce hierarchies of states

David Harel
Weizmann Institute of Science, Israel

State charts (1987)


Also known as hierarchical state diagrams

7 2IX20 Lecture 4
States and transitions

• States
• Transitions
• Guards
• Events
• Activities

8 2IX20 Lecture 4
State

• States = nodes of state machine


• When state is active
• Object is in that state
• All internal activities specified in this state can be executed
• An activity can consist of multiple actions

• 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

Change from one state to another


Event Guard Sequence of actions (effect)

Source state Transition Target state

10 2IX20 State machine diagrams: states and transitions


Transition – Syntax

• Event (trigger)
• Exogenous stimulus
• Can trigger state transition

• Activity (effect)
• Sequence of actions executed during state transition

11 2IX20 State machine diagrams: states and transitions


Transition – Syntax

• 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

12 2IX20 State machine diagrams: states and transitions


Transition – Types (1/2)
Internal transition External transition

• If event1 occurs • If event1 occurs


• Object remains in state1 • Object leaves state1 and
• Activity3 is executed Activity2 is executed
• Activity3 is executed
• Object enters state1 and
Activity1 is executed

13 2IX20 State machine diagrams: states and transitions


Transition – Types (2/2)
When do the following transitions take place?
If e1 occurs, A1 is aborted and the object changes to S2

If e1 occurs and g1 evaluates to true, A1 is aborted and the


object changes to S2

As soon as the execution of A1 is finished, a completion event is


generated that initiates the transition to S2

As soon as the execution of A1 is finished, a completion event is


generated; if g1 evaluates to true, the transition takes place; If
not, this transition can never happen
14 2IX20 State machine diagrams: states and transitions
Transition – Sequence of Activity Executions

Assume we first initialize S1 … what is the value of x after e occurred?

15 2IX20 State machine diagrams: states and transitions


Transition – Sequence of Activity Executions

Assume we first initialize S1 … what is the value of x after e occurred?


S1 becomes active, x is set to the value 4

16 2IX20 State machine diagrams: states and transitions


Transition – Sequence of Activity Executions

Assume S1 is active … what is the value of x after e occurred?


S1 becomes active, x is set to the value 4
e occurs, the guard is checked and evaluates to true

17 2IX20 State machine diagrams: states and transitions


Transition – Sequence of Activity Executions

Assume S1 is active … what is the value of x after e occurred?


S1 becomes active, x is set to the value 4
e occurs, the guard is checked and evaluates to true
S1 is left, x is set to 5

18 2IX20 State machine diagrams: states and transitions


Transition – Sequence of Activity Executions

Assume S1 is active … what is the value of x after e occurred?


S1 becomes active, x is set to the value 4
e occurs, the guard is checked and evaluates to true
S1 is left, x is set to 5
The transition takes place, x is set to 10

19 2IX20 State machine diagrams: states and transitions


Transition – Sequence of Activity Executions

Assume S1 is active … what is the value of x after e occurred?


S1 becomes active, x is set to the value 4
e occurs, the guard is checked and evaluates to true
S1 is left, x is set to 5
The transition takes place, x is set to 10
S2 is entered, x is set to 11

20 2IX20 State machine diagrams: states and transitions


Example: Registration Status of an Exam

21 2IX20 State machine diagrams: states and transitions


Event – Types (1/2)

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)

22 2IX20 State machine diagrams: states and transitions


Event – Types (2/2)

Any receive event


• Occurs when any event occurs that does not trigger other transition
from active state
• Keyword all
Completion event
• Generated automatically when everything to be done in current state is
completed
Change event
• Permanently checking whether condition becomes true
• E.g., when(x > y), after(90min)

23 2IX20 State machine diagrams: states and transitions


Change Event vs. Guard
Checked permanently

Only checked when event occurs

24 2IX20 State machine diagrams: states and transitions


Change Event vs. Guard
Checked permanently

Only checked when event occurs


Question: What if the lecture is shorter than 90min?

25 2IX20 State machine diagrams: states and transitions


Special states and pseudo-states

• Initial state
• Final state
• Terminal node
• Decision node
• Parallelization

26 2IX20 Lecture 4
Initial State

• “Start” of state machine diagram


• Pseudostate
• Transient; system cannot remain in that state
• Rather control structure than real state
• No incoming edges
• If >1 outgoing edges
• Guards must be mutually exclusive and cover all possible cases to ensure that
exactly one target state is reached
• If initial state becomes active, object immediately switches to next state
• No events allowed on outgoing edges (exception: new())

27 2IX20 State machine diagrams: types of states


Final State and Terminate Node

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)

28 2IX20 State machine diagrams: types of states


Decision Node

• Pseudostate
• Used to model alternative transitions
equivalent?

29 2IX20 State machine diagrams: types of states


Decision Node

• Pseudostate
• Used to model alternative transitions
equivalent?

30 2IX20 State machine diagrams: types of states


Decision Node

• Pseudostate
• Used to model alternative transitions
equivalent?

=
equivalent?

31 2IX20 State machine diagrams: types of states


Decision Node

• Pseudostate
• Used to model alternative transitions
equivalent?

=
equivalent?


32 2IX20 State machine diagrams: types of states
Example: Decision Node

33 2IX20 State machine diagrams: types of states


Parallelization and Synchronization 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

35 2IX20 State machine diagrams: types of states


Example: Entry and Exit Points

36 2IX20 State machine diagrams: types of states


Notation Elements (1/2)
Name Notation Description

Description of a specific “time span” in which an


State object finds itself during its “life cycle”. Within a
state, activities can be executed by the object.

Initial state Start of a state machine diagram

Final state End of a state machine diagram

Terminate node Termination of an object’s state machine diagram

37 2IX20 State machine diagrams: types of states


Notation Elements (2/2)
Name Syntax Beschreibung

Node from which multiple alternative


Decision node
transitions can origin

Splitting of a transition into multiple


Parallelization node
parallel transitions

Merging of multiple parallel transitions


Synchronization node
into one transition

38 2IX20 State machine diagrams: types of states


Adding hierarchy to state machines

39 2IX20 Lecture 4
Composite State

• Synonyms: complex state, nested state


• Contains other states – “substates“
• Only one substate active at any time
• Arbitrary nesting depth of substates
Composite state

Substates

40 2IX20 State machine diagrams: types of states


Configuration

• In hierarchical state machine diagram we can be in multiple states at a time


• Configuration: a valid combination of (sub)states

• Configurations: 𝑆3 , 𝑆1, 𝑆1.1 , 𝑆1, 𝑆1.2 , {𝑆2}

41 2IX20 State machine diagrams: types of states


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }

42 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }

43 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2

44 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2

45 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 a0

46 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 a0-a2

47 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 a0-a2-a3

48 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 a0-a2-a3

49 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 a0-a2-a3-a4

50 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (1/2)
Event Config. Executed
Transition to the boundary Activities
• Initial node of composite state is activated „Beginning“ { S3 }
e2 { S1, S1.1 } a0-a2-a3-a4

51 2IX20 State machine diagrams: composite states and sequences of actions


Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }

52 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1

53 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1 a0

54 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1 a0-a1

55 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1 a0-a1-a3

56 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1 a0-a1-a3-a7

57 2IX20 State machine diagrams: composite states and sequences of actions


23
Entering a Composite State (2/2)
Event Config. Executed
Transition to a substate Activities
• Substate is activated „Beginning“ { S3 }
e1 { S1,S1.2 } a0-a1-a3-a7

58 2IX20 State machine diagrams: composite states and sequences of actions


23
Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1 } a3-a4
e3

59 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1} a3-a4
e3 a6

60 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1 } a3-a4
e3 a6-a5

61 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1 } a3-a4
e3 a6-a5-a2

62 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1 } a3-a4
e3 a6-a5-a2-a1

63 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (1/3)
Event Config. Executed
Transition from substate Activities
„Beginning“ { S1,S1.1 } a3-a4
e3 { S2 } a6-a5-a2-a1

64 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

65 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5 a6
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

66 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5 a6-a5
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

67 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5 a6-a5-a3
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

68 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5 a6-a5-a3-a1
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

69 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (2/3)
Event Config. Executed
Activities
Transition from the composite state „Beginning“ { S1,S1.1 } a3-a4
No matter which e5 { S2 } a6-a5-a3-a1
substate of S1 is
active, as soon as e5
occurs, the system
changes to S2

70 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4

71 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 a6

72 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 a6

73 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7

74 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4

75 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 a8

76 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 a8

77 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 a8-a5

78 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 a8-a5

79 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 a8-a5-a1

80 2IX20 State machine diagrams: composite states and sequences of actions


Exiting from a Composite State (3/3)
Event Config. Executed
Activities
Completion transition from the composite state
„Beginning“ { S1,S1.1 } a3-a4
e4 { S1,S1.2 } a6-a7
e4 { S2 } a8-a5-a1

81 2IX20 State machine diagrams: composite states and sequences of actions


Orthogonal State

• 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

Using parallelization and


synchronization node to
enter different substates

82 2IX20 State machine diagrams: composite states and sequences of actions


Submachine State (SMS)

• To reuse parts of state machine diagrams in other state machine diagrams


• Notation: state:submachineState
• When submachine state activated, behavior of submachine is executed
• Corresponds to calling a subroutine in programming languages

Refinement symbol
(optional)

83 2IX20 State machine diagrams: composite states and sequences of actions


History State

• Remembers which substate of composite state was last active


• Activates “old” substate; all entry activities are conducted sequentially from
outside to inside of composite state
• Exactly one outgoing edge of history state points to a substate which is used if
• composite state was never active before
• composite state was exited via final state
• Shallow history state restores state that is on same level of composite state

• Deep history state restores last active substate over the entire nesting depth

84 2IX20 State machine diagrams: composite states and sequences of actions


Example: History State (1/4)

Event Config
„Beginning“ { S5 }
e1 { S4,S1,S1.1 }
e2 { S4,S1,S1.2 }
e10 { S5 }
e9 (H→) {S4, S1,S1.1}

85 2IX20 State machine diagrams: composite states and sequences of actions


Example: History State (2/4)

Event Config.
„Beginning“ { S5 }
e1 { S4,S1,S1.1 }
e2 { S4,S1,S1.2 }
e10 { S5 }
e8 (H*→) { S4,S1,S1.2 }

86 2IX20 State machine diagrams: composite states and sequences of actions


Example: History State (3/4)

Event Config.
„Beginning“ { S5 }
e9 (H→) { S4,S1,S1.1}

87 2IX20 State machine diagrams: composite states and sequences of actions


Example: History State (4/4)

Event Config.
„Beginning“ { S5 }
e8 (H*→) { S4,S3,S3.1 }

88 2IX20 State machine diagrams: composite states and sequences of actions


Summary

• State machine diagrams key Read


technique to model behavior • Chapter 6 reader/Chapter 5
of systems UML@Classroom
• States, pseudo-states, Do
transitions, hierarchy • Weekly test 2
• Events/Activities • Exercises 6.1-6.7
• Assignment 1: Finish use cases, class
• Be careful of execution order diagrams; prepare state machine
when reasoning about state diagrams
machien diagrams Look around for software bugs and send
them to me
89 2IX20 Lecture 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy