1 software engineering dr. k. t. tsang lecture 8 state modeling kentsang/swe/swe.htm

21
1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling http://www.uic.edu.hk/~kentsang/SWE/SWE.htm

Upload: bethany-chase

Post on 30-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

1

Software EngineeringDr. K. T. Tsang

Lecture 8

State modelinghttp://www.uic.edu.hk/~kentsang/SWE/SWE.htm

Page 2: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Events

• An event is an occurrence at a point in time.

• It happens instantaneously compared with the time scale in time, can be considered as atomic.

Page 3: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Signal event• A signal is a one-way transmission of information

from one object to another.• A signal event is the event of sending or receiving a

signal.• Signals can be grouped into signal classes, to show

common structure and behavior.• The UML notation is:

<<signal>>MouseButtonPushed

buttonlocation

Page 4: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

• A change event is an event caused by the satisfaction of a boolean expression.

• The underlying expression is continually tested.

• Whenever the expression changes from false to true, the event happens.

• The UML notation for change event is:

Change event

when (roomTemperature < heating_set_point)

Page 5: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

States • A “State” is an abstraction (a group) of values and

links of an object, that characterizes its gross behavior, e.g. – a bank is either solvent or insolvent, depending on

whether its assets exceed its liability;– a phone line is in a state of dialing or waiting

depending on whether the receiver is lifted or not.

• States are equivalence classes of values and links for an object.

• State model specifies allowable sequence of changes to objects of a given class.

• The UML notation for a state is a rounded box.

Page 6: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Life of an object & its states• Objects in a class have a finite number of states.• During the lifetime of an object, it can only be in

one state at a time. It may parade from one state to another.

• Events are points in time, and states are intervals of time.

• Events mark the beginning and end of a state.

timereceiver lifted first digit dialed

Dial tone Dialing Waiting

States of a phone-line

events

Page 7: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Transition• A transition is an instantaneous change from

one state to another.

• A transition is fired when an object changes from the source state to the target state.

• A guard condition is a boolean expression that must be true in order for a transition to occur.

Page 8: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Guard condition in transition: example

North/south maygo straight

North/south mayturn left

East/west mayturn left East/west may

go straight

timeout timeout

timeout [cars in E/W left lanes]

timeout [cars in N/S left lanes]

timeout [no car in

E/W left lanes]

timeout [no car in

N/S left lanes]

Traffic control signals

Fig.5.7 p.95 B&R

Page 9: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

State diagrams -- A graph whose nodes are states and whose directed arcs are transitions between states.

• It specifies the state sequences cause by event sequences.

• A state diagram describes all or part of the behavior of the objects of a given class.

• State names must be unique within scope of a state diagram.

Page 10: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

State diagram: example- a phone line

Fig.5.8 p.97

(no nested states)

Page 11: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

State diagram example: chess

White’s turn

Black’s turn

Black moreWhite more

checkmate

checkmate

stalemate

stalemate

Fig.5.9 p.98

Page 12: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

State diagram example: chess

White’s turn

Black’s turn

Black moreWhite more

checkmate

checkmate

stalemate

stalemate

X

X

XBlack wins

White wins

draw

Start

Fig.5.10 p.98With entry & exit points

Page 13: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Activities & effects

• An effect is a behavior executed in response to an event.

• An activity is the behavior that can be invoked by any number of effects.

• An activity may be performed upon a transition, upon the entry or exit from a state, or upon some other event within a state.

• Notation: a slash “/” and the name of the activity, following the event that causes it.

Page 14: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Example - activities

Idle Menu visible

Right button up / erase pop-up menu

Right button down / display pop-up menu

Cursor moved / highlight menu item

Activities for pop-up menu

Fig.5.12 p.100

Self-transition

Page 15: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Do-Activities

• A do-activity is an activity that continues for an extended time.

Paper jamdo / flash warning light

Page 16: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Entry & exit activities

Closed

Opening

Open

Closing

Door closed / motor off

Door open / motor offDepress / motor up

Depress / motor down

Garage door opener – example fig.5.14 p.101

Activities following events

Page 17: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Entry & exit activities

Closedentry / motor off

Openingentry / motor up

Openentry / motor off

Closingentry / motor down

Door closed

Door openDepress

Depress

Garage door opener – example fig.5.15 p.101

Activities bound to entry of states

Page 18: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

More on events & activities

• Event can occur within a state and causes activity to be performed.

• Entry & exit are only 2 examples of events that can occur.

• Self-transition states cause the entry/exit activities to be executed.

Page 19: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Completion transition

• Often the sole purpose of a state is to perform a sequential activity.

• An arrow without an event name is an automatic transition that fires when the activities associated with source state is completed.

• This kind of transition is called “Completion transition”.

Page 20: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Signals

• An object can send a signal (this action is an activity) to other object/objects (single object or a set of objects).

• If the target is a group of objects, each of them receives a copy of the signal concurrently, and responses independently.

• If an object can receive signals from more than one object, the order in which concurrent signals are received may affect the final state - this is called a race condition.

• Concurrent systems may contain unwanted race conditions that must be avoided by careful design.

Page 21: 1 Software Engineering Dr. K. T. Tsang Lecture 8 State modeling kentsang/SWE/SWE.htm

Reading for this lecture

• Chapter 5 Blaha & Rumbaugh