You are on page 1of 22

State Modeling & Advanced State Modeling

Object-Oriented Modeling and Design with UML; Michael Blaha, James Rumbaugh

2006. 4. 11 Seok-Joong Woo

Contents
Introduction State diagrams Events States Transitions and conditions State diagram behavior Concurrency Summary

2006-04-11

2/22

Introduction (1/2)
State model
Describes sequences of operations that occur in response to external stimuli Consists of multiple state diagrams, one for each class with behavior

State diagram
Graphical representation of finite state machines relates events and states

2006-04-11

3/22

Introduction (2/2)
Finite state machine
Model of behavior composed of states, transitions and actions

2006-04-11

4/22

State diagrams (1/2)


Definition
Graph that consists of nodes are states and transitions between states

Specification the state sequences by event sequence onHook Representation


Continuous loops
Idle offHook DialTone digit(n) Dialing timeout timeout Warning

Timeout

invalidNumber validNumber Recorded Message Connecting 2006-04-11 5/22

State diagrams (2/2)


Representation (contd)
One-shot life cycle
Chess Objects with finite lives Whites turn black moves white moves checkmate stalemate

Blacks turn checkmate Chess Using entry & Exit points Start checkmate Whites turn black moves white moves stalemate Black wins Draw White wins 6/22

Blacks turn

checkmate

2006-04-11

Events (1/4)
Definition
Occurrence at a point in time
Following another event Two events related or unrelated

Inclusion error condition and normal occurrences

Several kinds of events


Signal event Change event Time event

2006-04-11

7/22

Events (2/4)
Signal Event
Event of sending or receiving a signal Attributes indicating the values
<<signal>> FlightDeparture flightNumber city date <<signal>> MouseButtonPushed button location

Signals generalization
Hierarchy with inheritance of signal attributes

2006-04-11

8/22

Events (3/4)
Signals generalization Signal Event

UserInput Event of sending or receiving a signal device Attributes indicating the values

<<signal>>

<<signal>> FlightDeparture <<signal>> <<signal>> flightNumber MouseButton FightDeparture city flightNumber location date city date
MouseButtonDown
<<signal>> <<signal>> Signals generalization

<<signal>> MouseButtonPushed <<signal>> <<signal>> MouseButtonPushed button KeyboardCharacter button location character location
<<signal>> <<signal>>

Hierarchy with inheritance of signal attributes

MouseButUp

Control

Graphic

<<signal>>

Space

Alphanumeric

<<signal>>

Punctuation 9/22

<<signal>>

2006-04-11

Events (4/4)
Change Event
Satisfaction of a boolean expression
When (room temperature<heating set point) When (tire pressure<minimum pressure)

Time Event
Satisfaction of a time expression
When (date = January 1, 2000) After (10 seconds)

2006-04-11

10/22

States (1/3)
Definition
Abstraction of the value and links of an object
Solvent Insolvent Dial tone Dialing Powered

Response of object to input event Kinds of states


Simple state Composite state Submachine state

2006-04-11

11/22

States (2/3)
Simple state
No nested substates
Waiting Dialing Powered

Composite state
One or more region One or more nested substates

2006-04-11

12/22

States (3/3)
Submachine state
Reference a submachine another state machine
Idle Collecting money coins in(amount) / add to balance

Submachine state Submachine


Dispenseltem

do / test item and compute change

dispense: Dispenseitem

do / make change

do / move arm to correct row do / push item off shelf 2006-04-11

do/move arm to correct column

13/22

Transitions and conditions (1/3)


Transitions
Relationship between two states
Indicates the way an object in a state responds to event
Ringing Called phone event Connected

Structures of transitions
Source state SelectMode click(point) / select(point) trigger effect target state SelectMode

double-click[self.selection exists] / launch(self.selection) guard condition SelectMode


2006-04-11 14/22

Transitions and conditions (2/3)


Completion transition
Transition of source states activity completion
Idle Insert card Selecting pick date/add to selection pushdone cancel / eject card

/reset election

Choose

completion transition Selected


2006-04-11 15/22

Transitions and conditions (3/3)


Conditions
Boolean expression Occurrence of transition
North/south May go straight timeout[cars in N/S left lanes] North/south May turn left

timeout[no cars

timeout

timeout[no cars in E/W left lanes]

in N/S left lanes]

timeout

East/west May turn left

timeout[cars in E/W left lanes]

East/west May go straight

2006-04-11

16/22

State diagram behavior (1/2)


Activity effects
Activity is invoked by any number of effects Effect is executed in response to an event
Right button down / display pop-up menu Idle Right button up / erase pop-up menu event activity Menu visible Cursor moved / highlight menu item

Do-activities
Activity that continues for an extended time
Paper jam do / flash warning light
2006-04-11 17/22

State diagram behavior (2/2)


Activities on transition or entry to state
depress / motor up Closed door closed / motor off Opening door open / motor off Open depress / motor up Closing

depress / motor down

Activities on transition
Opening entry/motor up door open Open entry/motor off depress

depress Closed entry/motor up door closed

depress Closing entry/motor down

Activities on entry to states


2006-04-11 18/22

Concurrency (1/3)
Definition

Performance of two or more activities

Aggregation concurrency
State diagram for an assembly of state diagram, one for each part
Car 1 Ignition Ignition Off 1 Transmission 1 1 Accelerator 1 Brake release key Starting On

turn key to start [Transmission in Neutral] turn key off

2006-04-11

19/22

Concurrency (2/3)
Concurrency within an object
Partition some object into subsets of attributes or links, each of which has its own subdiagram
Bridge Playing rubber N-S vulnerability Not vulnerable E-W vulnerability Not vulnerable N-S game vulnerable E-W game vulnerable N-S game N-S wins rubber E-W game E-W wins rubber

2006-04-11

20/22

Concurrency (3/3)
Synchronization of concurrent activities
Complete both activities before it can progress to its next state Control can split into concurrent activities that subsequently merge
CashDispenser

Emitting do / dispense cash Ready to reset do / eject card

ready Setting up

2006-04-11

21/22

Summary
State diagram consists of
States Events Guard conditions Activities

Advanced State Modeling using


Expanding, Nested states Signal Generalization Concurrency

2006-04-11

22/22

You might also like