state transition diagrams

24
State Transition Diagrams Dynamic Modelling

Upload: havard

Post on 25-Feb-2016

43 views

Category:

Documents


0 download

DESCRIPTION

State Transition Diagrams. Dynamic Modelling. An object’s state and behaviour can be affected by: Changes to attribute values Results of operations Changes of links with other objects Internal events External events. Three models. Object model: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: State Transition Diagrams

State Transition Diagrams

Dynamic Modelling

Page 2: State Transition Diagrams

2

• An object’s state and behaviour can be affected by:– Changes to attribute values– Results of operations– Changes of links with other objects– Internal events– External events

Page 3: State Transition Diagrams

3

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

Page 4: State Transition Diagrams

4

Dynamic modelling

• Events• states• state diagrams• conditions• operations

Page 5: State Transition Diagrams

5

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

Page 6: State Transition Diagrams

6

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

Page 7: State Transition Diagrams

7

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

Page 8: State Transition Diagrams

8

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 it’s assets exceed it’s liabilities.

• A state corresponds to the interval between 2 events received by an object.– A state separates 2 events.– An event separates 2 states.

Page 9: State Transition Diagrams

9

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

Page 10: State Transition Diagrams

10

Condition that characterises the state:

alarm = on, and target time <= current time <= target

time + 20sand button has not been pushed since the

target time

Page 11: State Transition Diagrams

11

Events accepted in the state:

event action next state

current time = target time + 20s reset alarmnormal

button pushed (any button) reset alarm normal

Page 12: State Transition Diagrams

12

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

Page 13: State Transition Diagrams

State Transition DiagramIdle

Dial tonedo : Sound dial tonedo : Sound dial tone

Connectingdo : find connectiondo : find connection

ringingdo : ring belldo : ring bell

Connected

Disconnected

Busy tonedo : slow busy tonedo : slow busy tone

Fast busy tonedo : play fast busy tonedo : play fast busy tone

Time outdo : sound loud beepdo : sound loud beep

Recorded messagedo : Play messagedo : Play message

Dialling

off-hook

routed

called phone answers/connect line

called phone hangs up/disconnect line

on-hook

time-out

digit (n)time-out

message done

digit (n)

valid numberinvalid number

trunk busy

on-hook/disconnect line

number busy

Page 14: State Transition Diagrams

14

Initial/final States

• The previous example is a continuous loop• Most situations will have an initial and final

state• Chess game

White's turn

Black's turn

white wins

Black wins

Draw

Start Whitemoves

Blackmoves

checkmate

stalemate

stalemate

Checkmate

Page 15: State Transition Diagrams

15

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).

Page 16: State Transition Diagrams

16

Traffic light

North/south may go straight

East/west may turn right

North/south may turn right

East/west may go straight

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

time-out[no carsin E/W right lanes]

time-out

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

Time out[cars in E/W right lanes]

Time-out

State Transition Diagram With Conditions

Page 17: State Transition Diagrams

17

Operations

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

Page 18: State Transition Diagrams

18

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.”

Page 19: State Transition Diagrams

Telephone call

Idle

Dial tone

do: Sound dial tone

Connecting

do: find connection

ringing

do: ring bell

Connected

Disconnected

Busy tone

do: slow busy tone

Fast busy tone

do: fast busy tone

Time out

do: sound loud beep

Recorded message

do: Play message

Dialling

off-hook

routed

called phone answers/connect line

called phone hangs up/disconnect line

on-hook

time-out

digit (n)time-out

message done

digit (n)

valid number

invalid number

trunk busy

on-hook/disconnect line

number busy

Page 20: State Transition Diagrams

20

Nesting Diagrams

• Done by generalising states– E.G. Aircraft in flight

• Done by generalising events– E.G. Booking clerk books flight

Page 21: State Transition Diagrams

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.

Page 22: State Transition Diagrams

22

Claim reported and Accident verified

Claim reported accident not verified

Claim rejected

Awaiting expert report

Claim reported

Reject

Refer to expert

Passed on to underwriter

Settled

Refer to underwriter

Accident verified

DeleteClaimTimePassedUndisputed

SettlementDisputed

Claim Dropped

TimePassedUndisputed

Report submitted

Page 23: State Transition Diagrams

23

States of Order

Order started

Order confirmed

Order deleted

Order cancelled

[ [orderline added] ] / Update total

/ order confirmed

Manufacture started

/ order raw material

All garments released

Order released

Payment made

[ not last payment ] / payment made[ paid in full ] / payment made

Page 24: State Transition Diagrams

24

States of Garment (Garments system)Garment ordered

Material ordered

Material delivered

Marked out for cutting

Cut

Marked out for sewing

Sewn

Marked out for finishing

Finished

Deleted