47
UML 2.0 STATE DIAGRAMS Concepts & Notations

UML 2.0 State Diagrams

  • Upload
    luke

  • View
    95

  • Download
    1

Embed Size (px)

DESCRIPTION

Concepts & Notations. UML 2.0 State Diagrams. Acknowledgements. The material in this tutorial is based in part on: Concurrency: State Models & Java Programming , by Jeff Magee and Jeff Kramer - PowerPoint PPT Presentation

Citation preview

Page 1: UML 2.0  State Diagrams

UML 2.0 STATE DIAGRAMS

Concepts & Notations

Page 2: UML 2.0  State Diagrams

Acknowledgements The material in this tutorial is based

in part on:Concurrency: State Models & Java

Programming, by Jeff Magee and Jeff Kramer

The Unified Modeling Language Reference Manual, 2nd edition, by James Rumbaugh, Ivar Jacobson, and Grady Booch

Page 3: UML 2.0  State Diagrams

UML State Diagram Finite-state Models State Machine View Events, Transitions, and States Examples

Page 4: UML 2.0  State Diagrams

Finite-state Models Represent the behavior of a system over

time

Specify controlIn terms of states, events, and transitionsTransitions occur only when they are enabled

Many variants existGraphical: State charts, UML state diagramsTextual: FSP

Page 5: UML 2.0  State Diagrams

State Machine View Describes dynamic behavior of objects over time

Describes states that objects may hold, and how they will react to events when in those states

Describes classes and corresponding instances Also behaviors, use cases, collaborations

A localized view External influences summarized as events

Page 6: UML 2.0  State Diagrams

Event, Transition & State Event

occurrence at a point in timeInstantaneousverbs of past tenseonset of a condition

Transition State

Page 7: UML 2.0  State Diagrams

Kinds of EventsType Description Syntax

call event Receipt of an explicit synchronous call request by an object

op (a:T)

change event

A change in value of a Boolean expression

when (exp)

signal event

Receipt of an explicit, named, asynchronous communication among objects

sname (a:T)

time event The arrival of an absolute time or the passage of a relative amount of time

after (time)

Page 8: UML 2.0  State Diagrams

Kinds of EventsType Description Syntax

call event Receipt of an explicit synchronous call request by an object

op (a:T)

change event

A change in value of a Boolean expression

when (exp)

signal event

Receipt of an explicit, named, asynchronous communication among objects

sname (a:T)

time event The arrival of an absolute time or the passage of a relative amount of time

after (time)

Page 9: UML 2.0  State Diagrams

Kinds of EventsType Description Syntax

call event Receipt of an explicit synchronous call request by an object

op (a:T)

change event

A change in value of a Boolean expression

when (exp)

signal event

Receipt of an explicit, named, asynchronous communication among objects

sname (a:T)

time event

The arrival of an absolute time or the passage of a relative amount of time

after (time)

Page 10: UML 2.0  State Diagrams

Kinds of EventsType Description Syntax

call event Receipt of an explicit synchronous call request by an object

op (a:T)

change event

A change in value of a Boolean expression

when (exp)

signal event

Receipt of an explicit, named, asynchronous communication among objects

sname (a:T)

time event

The arrival of an absolute time or the passage of a relative amount of time

after (time)

Page 11: UML 2.0  State Diagrams

Kinds of EventsType Description Syntax

call event Receipt of an explicit synchronous call request by an object

op (a:T)

change event

A change in value of a Boolean expression

when (exp)

signal event

Receipt of an explicit, named, asynchronous communication among objects

sname (a:T)

time event

The arrival of an absolute time or the passage of a relative amount of time

after (time)

Page 12: UML 2.0  State Diagrams

Event, Transition & State Event Transition

Instantaneous change in state4 key elements

○ event trigger○ guard condition○ effect○ target state

State

Page 13: UML 2.0  State Diagrams

Kinds of TransitionsTransition Type

Key point Syntax

entry transition do setup entry / effect

exit transition do clean up exit / effect

external transition

include entry / exit activity

e(a:T) [guard condition] / effect

internal transition

exclude entry / exit activity

e(a:T) [guard condition] / effect

Page 14: UML 2.0  State Diagrams

Kinds of TransitionsTransition Type

Key point Syntax

entry transition do setup entry / effect

exit transition do clean up exit / effect

external transition

include entry / exit activity

e(a:T) [guard condition] / effect

internal transition

exclude entry / exit activity

e(a:T) [guard condition] / effect

Page 15: UML 2.0  State Diagrams

Transition

S Tevent(attributes) [guard condition] / effect

Page 16: UML 2.0  State Diagrams

Transition

S Tevent(attributes) [guard condition] / effect

Page 17: UML 2.0  State Diagrams

Transition

S Tevent(attributes) [guard condition] / effect

Page 18: UML 2.0  State Diagrams

Transition

S Tevent(attributes) [guard condition] / effect

Page 19: UML 2.0  State Diagrams

Effects An effect may be an action or an

activity.action: a primitive computation

○ x = 3○ z = x+1○ sending a signal○ calling an operation○ new Widget(x,3)○ widg.getValue()○ widg.setValue(5);

Page 20: UML 2.0  State Diagrams

Effects An effect may be an action or an

activity.activity : a list of simpler actions or activities

○ the specification of executable behavior as the coordinated sequential and concurrent execution of subordinate units.

Page 21: UML 2.0  State Diagrams

Transition

S Tevent(attributes) [guard condition] / effect

Page 22: UML 2.0  State Diagrams

Multiple transitions Multiple transitions from the same state

may specify the same event triggeronly one transition may fire in response to

one event occurrenceeach transition with same event must have a

different guard conditionOften, conditions together cover all

possibilitiesIf an uncovered possibility occurs, the event

is ignored

Page 23: UML 2.0  State Diagrams

Not allowed …

State 1....

State 3

State 4

done

done

Page 24: UML 2.0  State Diagrams

CSE 335: Software Design

Uncovered possibilities …

State 1...

State 3

State 4

done [ x > 20]

done [ x < 10]

Page 25: UML 2.0  State Diagrams

Completion transition A transition that lacks an explicit trigger

event is triggered by the completion of activity

in the state that it leaves May have a guard condition takes priority over ordinary events

State 1 State 2

Page 26: UML 2.0  State Diagrams

Kinds of TransitionsTransition Type

Key point Syntax

entry transition

do setup entry / effect

exit transition do clean up exit / effect

external transition

include entry / exit activity

e(a:T) [guard condition] / effect

internal transition

exclude entry / exit activity

e(a:T) [guard condition] / effect

Page 27: UML 2.0  State Diagrams

Kinds of TransitionsTransition Type

Key point Syntax

entry transition do setup entry / effect

exit transition do clean up exit / effect

external transition

include entry / exit activity

e(a:T) [guard condition] / effect

internal transition

exclude entry / exit activity

e(a:T) [guard condition] / effect

Page 28: UML 2.0  State Diagrams

Kinds of TransitionsTransition Type

Key point Syntax

entry transition do setup entry / effect

exit transition do clean up exit / effect

external transition

include entry / exit activity

e(a:T) [guard condition] / effect

internal transition

exclude entry / exit activity

e(a:T) [guard condition] / effect

Page 29: UML 2.0  State Diagrams

ExamplesOpening

entry / motor upexit / motor off

Copyingentry / light up and scan

exit / light off

Print 10 copies

Copyingentry / light up and scan

exit / light off

Print 10 copies

figure 1

figure 2 figure 3

Page 30: UML 2.0  State Diagrams

Order of activities1. activities on incoming transition

2. entry activities

3. do-activities• execution of behavior within a state machine that is based on

holding a given state

• starts when the state is entered

• continues until the activity completes on its own or the state is exited

• not terminated by the firing of an internal transition

4. exit activities

5. activities on outgoing transition

Page 31: UML 2.0  State Diagrams

Event, State & Transition Event Transition State

behavioral condition that persists in timecorresponds to verbs with suffix of “-ing”an abstraction of values of attributes and

configuration of objects○ a set of object with similar values○ object waits for events○ object performs ongoing activity

Page 32: UML 2.0  State Diagrams

Kinds of States simple state

notation:

S

Page 33: UML 2.0  State Diagrams

Kinds of States initial state

notation:

Page 34: UML 2.0  State Diagrams

S

Kinds of States final state

notation:

Page 35: UML 2.0  State Diagrams

Example

White’sturn

Black’sturn

whitemoves

blackmoves

checkmate

checkmate

stalemate

stalemate

Chess game

start state

Default final state

simple state

Page 36: UML 2.0  State Diagrams

Example

White’sturn

Black’sturn

Blackwins

Whitewins

Drawwhite

movesblack

moves

checkmate

checkmate

stalemate

stalemate

Chess game

start state

Finalstates

Page 37: UML 2.0  State Diagrams

Kinds of States entry point

notation:

Ta

Page 38: UML 2.0  State Diagrams

Kinds of States exit point

notation:

Ub

Page 39: UML 2.0  State Diagrams

Example

White’sturn

Black’sturn

whitemoves

blackmoves

checkmate

checkmate

stalemate

stalemate

Chess game

Black wins

Draw

White wins

entry point exit point

Page 40: UML 2.0  State Diagrams

Kinds of States submachine state

notation:

s:M

Page 41: UML 2.0  State Diagrams

Examples

Help

CommandWait

run:Run help:Help

Main machine

submachine state submachine state

runcommand

helpcommand

entry / display help screenexit / remove help screen

quit

query / show answer

This submachine can be used many

times

submachine

Page 42: UML 2.0  State Diagrams

Composite State Introduces an abstract “super state”

decomposed into multiple sub-stateswhen the super state is active, exactly one

of its sub-states is active

Page 43: UML 2.0  State Diagrams

Composite State nonorthogonal state

S

Page 44: UML 2.0  State Diagrams

Composite State orthogonal state

S

Page 45: UML 2.0  State Diagrams

Examples

Ready

Running

Terminated

Waiting

dispatch yiel

d

Runnable

resume

suspend

stop

Created

stop

start

end

Thread

stop

Page 46: UML 2.0  State Diagrams

Examples

TempOff

Automobile

Cooling

Heating

pushHeat pushAir

TempOn

pushHeat

pushAir

pushTCOff

Temperature control

Rear defroster

RDOff RDOnpushRD

pushRDRadOff RadOn

pushRad

pushRad

Radio control

Page 47: UML 2.0  State Diagrams

Review States, Events, Transitions

Firing rules Effects: actions and activities

Ordering of activities Simple, submachine, and composite

statesorthogonalnon-orthogonal