Introduction to PSP

Models & Analysis of Software
Lecture 6
Statecharts
[email protected]
www.cs.put.poznan.pl/jnawrocki/mss/
Copyright, 2003 © Jerzy R. Nawrocki
Plan of the lecture
• Introduction
•
•
•
•
•
•
•
Clustering and refinement
Orthogonality
Actions
Activities
Condition and selection entrances
Timeouts
Parameterised states
J. Nawrocki, Models of Software (6)
Introduction
Input
Transformational Output
system
output= f(input)
Stimuli
Reactive
Stimuli
system
STATE
J. Nawrocki, Models of Software (6)
Response
Response
Introduction
How about the
exponential
blow-up problem?
A
e(c)
e - event
c - condition
J. Nawrocki, Models of Software (6)
B
Introduction
Kind of statements that should
be taken into account:
• In all airborne states, when
yellow handle is pulled seat
will be ejected.
• Gearbox change of state is
independent of braking
system.
• Display-mode consists of
time-display, date-display and
stopwatch-display.
J. Nawrocki, Models of Software (6)
Introduction
In all airborne states, when
yellow handle is pulled seat
will be ejected.
Ability to cluster states into a
superstate.
J. Nawrocki, Models of Software (6)
Introduction
Gearbox change of state is
independent of braking
system.
Independence or
orthogonality.
J. Nawrocki, Models of Software (6)
Introduction
Display-mode consists of
time-display, date-display and
stopwatch-display.
Refinement of states.
J. Nawrocki, Models of Software (6)
Introduction
Statecharts = state-diagrams +
depth + orthogonality +
broadcast-communication
J. Nawrocki, Models of Software (6)
Plan of the lecture
• Introduction
• Clustering and refinement
•
•
•
•
•
•
•
Orthogonality
Summary
Actions
Activities
Condition and selection entrances
Timeouts
Parameterised states
J. Nawrocki, Models of Software (6)
Clustering and refinement
D
A
(P)
C
A


B


J. Nawrocki, Models of Software (6)
(P)
C



B
Clustering and refinement
D
D



B
A

D
A

C

J. Nawrocki, Models of Software (6)
B
(P)
C



B
Clustering and refinement
D
A
(P)
C
A


B

J. Nawrocki, Models of Software (6)
(P)
C
Clustering and refinement
D
A
(P)
C


D
B

J. Nawrocki, Models of Software (6)



B
Clustering and refinement
D
A

(P)
B

C
A


J. Nawrocki, Models of Software (6)
(P)
C



B
Clustering and refinement


C
H
C
A

H
A

B
J. Nawrocki, Models of Software (6)


B
Clustering and refinement


J
H
J
G
D
C
H *
G
D
C
A
E
A
E
B
F
B
F
J. Nawrocki, Models of Software (6)
Clustering and refinement

J
H

K
G
H *
H
C
D
C
A
D
G
A
E
B
F
E
B
F
J. Nawrocki, Models of Software (6)
Clustering and refinement
G
G
H
C
H
C
A

B
D
D
E
E
F
J. Nawrocki, Models of Software (6)

F
Clustering and refinement
G
G
H
C
H
C

D
D
E
E
F
J. Nawrocki, Models of Software (6)

F
Clustering and refinement

J
H
C
G
D
A
B
J. Nawrocki, Models of Software (6)
E
Plan of the lecture
• Introduction
• Clustering and refinement
• Orthogonality
•
•
•
•
•
Actions
Activities
Condition and selection entrances
Timeouts
Parameterised states
J. Nawrocki, Models of Software (6)
Orthogonality
D
A
E
B

(in G)

C
J. Nawrocki, Models of Software (6)

G


F

Orthogonality
D
A
E
B

(in G)


G
C

J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
 
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
  
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
  
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
  
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
  
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)


G
C
  
J. Nawrocki, Models of Software (6)


F

Orthogonality
D
A
E
B

(in G)

C
J. Nawrocki, Models of Software (6)

G


F

Plan of the lecture
• Introduction
• Clustering and refinement
• Orthogonality
• Actions
•
•
•
•
Activities
Condition and selection entrances
Timeouts
Parameterised states
J. Nawrocki, Models of Software (6)
Actions
Action:
• an instantaneous
occurrence
• ideally takes zero
time.
Examples:
• sending a signal,
• assignment statement.
J. Nawrocki, Models of Software (6)
A
e(c) / a
e - event
c - condition
a - action
B
Actions
x:
B
y:
Loop
while (x != y)
if (x > y)
x -= y;
else y -= x;
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
6
y:
9
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
6
y:
9
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
6
y:
9
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
6
y:
3
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
6
y:
3
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
3
y:
3
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
3
y:
3
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
x:
3
y:
3
B
Loop
(x>y) /
x-=y
X
S
(x=y)
E
J. Nawrocki, Models of Software (6)
(y>x) /
y-=x
Y
Actions
C
/w

A
B
entry s
entry v
exit , t
throughout x 
F
J. Nawrocki, Models of Software (6)
D

E
entry u
Actions
x:
B
y:
L
true(x>y)
X
entry x-=y
true(y>x)
S
Y
entry y-=x
true(x=y)
E
J. Nawrocki, Models of Software (6)
Plan of the lecture
•
•
•
•
Introduction
Clustering and refinement
Orthogonality
Actions
• Activities
• Condition and selection entrances
• Timeouts
• Parameterised states
J. Nawrocki, Models of Software (6)
Activities
Activity:
• similar to action but
• takes a nonzero amount of time
Examples:
• reading input
• beeping
• displaying
• lengthy computations
J. Nawrocki, Models of Software (6)
Activities
Actions
start(A)
Conditions
active(A)
Events
started(A)
stop(A)
hanging(A)
stopped(A)
suspend(A)
resume(A)
J. Nawrocki, Models of Software (6)
Activities
true(CT > R)
entry
start(Freeze)
J. Nawrocki, Models of Software (6)
true(CT < R)
entry
stop(Freeze)
Plan of the lecture
•
•
•
•
•
Introduction
Clustering and refinement
Orthogonality
Actions
Activities
• Condition and selection entrances
• Timeouts
• Parameterised states
J. Nawrocki, Models of Software (6)
Condition and selection entrances

 (d)
 (f)
 (e)
J. Nawrocki, Models of Software (6)
(d)
C
(e)
(f)
Condition and selection entrances



S
A
B
C
J. Nawrocki, Models of Software (6)
A
B
C
Plan of the lecture
•
•
•
•
•
•
Introduction
Clustering and refinement
Orthogonality
Actions
Activities
Condition and selection entrances
• Timeouts
• Parameterised states
J. Nawrocki, Models of Software (6)
Timeouts
timeout (event, number)
timeout (entered state, number)
< 2 sec.
J. Nawrocki, Models of Software (6)
timeout
Plan of the lecture
•
•
•
•
•
•
•
Introduction
Clustering and refinement
Orthogonality
Actions
Activities
Condition and selection entrances
Timeouts
• Parameterised states
J. Nawrocki, Models of Software (6)
Parameterised states
 9
0
 8

1
7


2
6

3
i  [0..9]

 4
 5
J. Nawrocki, Models of Software (6)

i+1
mod 10
i

Parameterised states
 9
0
 8


1
7


1

2
6

3

0
 4
 5
J. Nawrocki, Models of Software (6)
i  [1..8]

i
 i+1
9
Summary
Statecharts:
• Reactive systems
• State diagrams
• Clustering and refinement
• Orthogonality
J. Nawrocki, Models of Software (6)
Summary
Actions (short)
Activities (long)
Conditions and selections
Timeouts
Parameterised states
J. Nawrocki, Models of Software (6)
Further readings
D. Harel, Statecharts: A Visual
Formalism for Complex Systems,
Science of Computer
Programming, vol. 8 (1987) 231 274.
D. Harel et al., STATEMATE: A
working environment for the
development of complex reactive
systems, IEEE Transactions on
Software Eng.,vol. 16 (1990), no. 4,
403 - 414.
J. Nawrocki, Models of Software (6)
Homework
Describe your TV set with
statecharts.
Using statecharts solve the
problem of readers and
writers.
J. Nawrocki, Models of Software (6)
Quality assessment
1. What is your general
impression ?
2. Was it too slow or too fast ?
3. Did you learn something
important to you ?
4. What to improve and how ?
J. Nawrocki, Models of Software (6)