State Transition Diagrams: Dynamic Modelling

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

State Transition Diagrams

Dynamic Modelling
An objects state and behaviour can be
affected by:
Changes to attribute values
Results of operations
Changes of links with other objects
Internal events
External events

2
Three models

Object model:
Static structure of objects in a system and their
relationships.
Contains class diagrams.
dynamic model;
describes aspects that change over time: state
transition diagrams
functional model;
Use Case diagrams

3
Dynamic modelling

Events
states
state diagrams
conditions
operations

4
Events

Something that happens at a point in time


Mouse button clicked / Signal changes
Logically ordered events - causally related
Concurrent events - causally unrelated
do not effect each other
there is no order between them
1-way transmission of information from one
object to another

5
Event classes

Event occurrences are grouped into event


classes
Flight 123 departs from Chicago / Flight 456
departs from Rome
Event class is Flight Departs
Attributes of event classes
Departure origin of flight
Flight number
Data values are Attributes
6
Event Classes and Attributes

Aeroplane flight departs (airline, flight


no, city)
Mouse button pushed (button, location)
Input string entered (text)
phone receiver lifted
digit dialled (digit)
engine speed enters danger zone
7
States

A state is an abstraction of the attribute values and


links of an object. Sets of values are grouped
together into a state according to properties that
affect the gross behaviour of the object.
E.G.. A bank is solvent or insolvent depending on
whether its assets exceed its liabilities.
A state corresponds to the interval between 2 events
received by an object.
A state separates 2 events.
An event separates 2 states.

8
Characterisations of a state

State: Alarm ringing


Description: alarm on watch is ringing to
indicate target time
Event sequence that produces the state:
set alarm (target time)
any sequence not including clear alarm
current time = target time

9
Condition that characterises the
state:
alarm = on,
and
target time <= current time <= target time + 20s
and
button has not been pushed since the target
time

10
Events accepted in the state:

event action next state


current time = target time + 20s reset alarm normal
button pushed (any button) reset alarm normal

11
State Diagrams

Relates to a specific object


Relate states and events
A change of state is called a transition
All transitions leaving a state must
correspond to different events
The transition fires
An event that has no transition is ignored
A sequence of events corresponds to a path
through the graph
12
State Transition Diagram
Idle
on-hook

off-hook
Dial tone time-out Time out
do : Sound dial tone do : sound loud beep
digit (n)
digit (n)
time-out
Dialling
Recorded message
Busy tone invalid number
do : Play message
valid number
do : slow busy tone
trunk busy Connecting
do : find connection
number busy
routed
Fast busy tone ringing
do : play fast busy tone do : ring bell
message done
called phone answers
/connect line
Connected
on-hook/
disconnect line called phone hangs up
/disconnect line
Disconnected
Initial/final States

The previous example is a continuous loop


Most situations will have an initial and final state
Chess game

White's turn checkmate

Start stalemate white wins


White Black
moves moves
stalemate Draw
Black's turn
Checkmate
Black wins
14
Conditions

Used as guards on transitions.


A guarded transition only fires when the
condition is true e.g.
When you go out in the morning (event),
If the temperature is below freezing
(condition).
Put on your gloves (next state).

15
State Transition Diagram With
Conditions
Traffic light

time-out[cars in N/S right lanes]

North/south may go straight North/south may turn right

time-out time-out[no cars Time-out


in N/S right lanes]
time-out[no cars
in E/W right lanes]

East/west may turn right East/west may go straight


Time out[cars in E/W
right lanes]

16
Operations

Attached to state
Performed in response to the state
Attached to a transition
Performed in response to the event

17
Activities and Actions

An activity is an operation that takes time.


E.G.. Display a picture on a screen.
Do:a indicates that activity A occurs
throughout the lifetime of the state to which it is
attached.
An action is an instantaneous operation.
E.G.. Disconnect phone line.
An action is shown on a transition as action /
event.

18
T
e
e
l
p
ho
n
ec
a
l

o
n
h
-
o
o
kd
Ie
l

o
h
-
f
o
o
k
m
i
t
e
o
-u
t
D
a
i
o
t
l
ne T
m
i
eo
u
t
d
o
S
:
o
un
d
da
i
o
t
l
ned
os
:
o
un
d
o
l
ud
b
e
d
g
i
n
(
t
i
) d
g
i
n
(
t
i
)
m
i
te
o
-
ut
D
a
i
n
i
lg
R
e
co
d
r
ed
m
es
s
a
n
i
v
ad
i
l
n
um
b
er
B
u
s
yo
t
n
e
d
o
P
:a
l
y
me
s
sa
g
e
va
d
i
l
n
um
b
er
d
o
s
:
o
l
w
bu
s
yo
t
n
e
n
u
mb
e
b
ru
s
y
Co
n
n
ec
n
i
t
g
do
n
i
f
:
d
co
n
ne
c
o
i
t
n
r
t
un
k
bu
s
y
o
ru
e
td
F
a
s
b
t
u
s
yo
t
n
e n
i
r
g
n
ig
d
o
a
f
:
s
b
t
us
y
o
tn
ed
o
n
i
r
:
g
be
l m
es
s
a
ge
d
c
ae
l
dp
h
o
ne
a
n
sw
e
r
s
c
/
on
ne
c
n
i
l
t
e

Co
n
n
e
c
e
td
o
n
h
-
oo
k
/
d
s
i
c
on
n
ec
n
i
l
t
e c
a
e
l
dp
h
on
e
h
an
g
su
p
d
/
s
i
c
on
n
ec
n
i
l
t
e

D
s
i
c
on
n
ec
e
t
d
Nesting Diagrams

Done by generalising states


E.G. Aircraft in flight
Done by generalising events
E.G. Booking clerk books flight

20
Exercise 1 - Claims
A third party claim arises from an incident that has occurred.
The claim must be reported to the claims office within the
statutory period to be valid. When the claim is reported, the
incident is preferably verified by a member of staff who was
present at the time. The claim is recorded and evaluated. If it is
a trivial claim, the claims assessor checks the claimant for
previous claims and, if there are no or 1 previous claims then a
payment is made and the claim is settled. If there are previous
claims, the claimant will be referred to the courts. More serious
claims may await expert evidence and several different court
hearings. At any stage, the claim may be dropped, or a
payment made without admitting liability. If the claimant is a
minor, the claim must remain on the books until the claimant is
over 21. If a claim is settled by a court, it may be appealed.
During this time, the claim remains open.
Draw a state diagram for a claim.
Claim reported Claim reported
accident not verified

Claim
Accident verified Dropped

Claim reported and


Accident verified Refer to expert
Awaiting expert
report

Report submitted

Refer to underwriter

Reject Settled
SettlementDisputed Passed on to
underwriter

TimePassedUndisputed
DeleteClaim
Claim rejected

TimePassedUndisputed

22
States of Order
[ [orderline added] ] / Update total

Order Order cancelled


started Order
deleted
/ order confirmed
Order
confirmed [ paid in full ] / payment made
[ not last payment ] / payment made
/ order raw material
Manufactur
e started

All garments
released
Payment
made
Order
released 23
States of Garment (Garments
system) Marked out for
Garment
finishing
ordered

Material Sewn
ordered
Finished

Material Marked out for


delivered sewing
Deleted

Marked out for Cut


cutting

24

You might also like