Beruflich Dokumente
Kultur Dokumente
By Kendra Cooper
Contents
Introduction
State Diagrams
Depth (hierarchy)
Orthogonality (concurrency)
Broadcast Communication
Example
Problems
Introduction
Statecharts were introduced by David Harel in 1987
D. Harel, Statecharts: A visual formalism for complex systems, Science
of Computer Programming 8, 1987, pp. 231-274.
Depth (hierarchy)
statecharts extend this with:
o refinement, clustering
o AND, OR decomposition of states
(actually XOR, not OR)
Example (clustering, bottom up approach)
b
A
a
e(P)
d
C
e(P)
D is called a superstate.
The semantics (aka meaning) of superstate D is:
o A xor C
The arc labeled b is a common property to the superstate D
D
A
b
C
D
A
e(P)
C
Default state
If we have substates A, B, and C and we want to enter state A by default, we
specify this using a small arrow:
A
or
History State
Can use a history entrance (H). The state entered is the last state the level was
in when it existed.
The H entrance overrides a default state
The scope of the H entrance is the current level of the diagram
The scope of the H* entrance is to the lowest level of the diagram.
D
A
B
C
Example:
a timer that continues to count down as the state is entered and exited
(the timer does not get reset when the state is entered)
Orthogonality (concurrency)
AND
Example
Y is the orthogonal product of A and D
Y
D
A
A
a
b
C
E
g
d
G
F
a
Button 1&2
Blink
Hours
Button 1
Increment
Button 2 Hours
Button 2
Button 1
Blink
Minutes
Button 2
Button 2
Button 1
Button 1&2 Blink
Seconds
Button 2
Button 1&2
CurrentTime
Set
Button 1
Increment
Minutes
Button 1
Increment
Seconds
Button 1
Button 1&2
Blink
Hours
Button 1
Button 2
Button 2
Button 1
Button 1&2 Blink
Minutes
Button 2
Button 2
Button 1
Button 1&2 Blink
Seconds
Button 2
Increment
Hours
Button 1
Increment
Minutes
Button 1
Increment
Seconds
Button 1
Alarm Time
Set
xor
Clock
Display Time
Button 1
Set Current
Time
Display
Alarm Time
Button 2
Clock
Display Time
Alarm
Time
Alarm On
Button 1
Button 1
Set Current
Time
Button 2
Set
Alarm
Now, validate the behavior of the statechart (i.e., does the statechart specify the
system the way we want it to work)
Question: What happens if the alarm goes off for 5 minutes?
Display vs. Maintain the time?
Maintaining the time needs to occur concurrently with:
the alarm going off
setting the alarm time
Question: Is it possible to display and maintain the current time concurrently?
Next step is to fix the statechart.
After it is fixed, need to re-validate the statechart.
Other things to consider:
Is there a radio?
Is there a snooze button?
Is there a battery backup?
.
HW Exercise: complete the statechart.
Problems
1. What is a statechart?
2. Describe 3 types of systems that would be suitable for describing in
statecharts.
3. In software engineering, we use the principle of abstraction. How does
statecharts support this principle?
4. Draw a statechart that specifies the functionality of a digital
watch that has an alarm feature (i.e., you can set the time for a beeping alarm to
go off).
2. Draw a statechart that specifies the functionality of a four function calculator.
3. Draw a Statechart that represents the Dining Philosophers Problem.
The Dining Philosophers Problem
Five philosophers sit at a round table. At any given time, a philosopher may
either eat or meditate. When they eat, they need to pick up two chopsticks (one
on their left and one on their right). When they meditate, they do not need any
chopsticks. There are a total of five chopsticks available.