1 software engineering dr. k. t. tsang lecture 8 state modeling kentsang/swe/swe.htm
TRANSCRIPT
1
Software EngineeringDr. K. T. Tsang
Lecture 8
State modelinghttp://www.uic.edu.hk/~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.
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
• 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)
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.
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
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.
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
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.
State diagram: example- a phone line
Fig.5.8 p.97
(no nested states)
State diagram example: chess
White’s turn
Black’s turn
Black moreWhite more
checkmate
checkmate
stalemate
stalemate
Fig.5.9 p.98
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
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.
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
Do-Activities
• A do-activity is an activity that continues for an extended time.
Paper jamdo / flash warning light
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
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
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.
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”.
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.
Reading for this lecture
• Chapter 5 Blaha & Rumbaugh