A Methodology for Structured Use-centered Quantitative

advertisement
Fall 2010
CS4310 Requirements Engineering
UML: Dynamic Modeling
Dr. Guoqiang Hu
Department of Computer Science
UTEP
1
Outline:
1. Key Concepts & Their UML Notations
2. Basic State Diagram UML Notations
3. Examples
4. Exercises
5. Nested State Diagram, Nested State
6. Sequence Diagram
7. Activity Diagram
2
1 Key Concepts & Their UML Notations
1.1 State model
Describes the sequences of operations of objects that occur in
response to stimuli
Consists of multiple state diagrams, one for each class with
temporal behavior that is important to an application
1.2 State
An abstraction of the values and links of an object: sets of
values and links grouped together into a state according to the
gross behavior of the object
Ignore attributes that do not affect the behavior of the object,
and lump together in a single state all combinations of values
and links with the same response to events
Solvent
Insolvent
Waiting
Dialing
Powered
3
1.3 Event
An occurrence at a point in time
Can be causally related or unrelated (concurrent)
The most common types of event:
1. Signal event: Sending or receiving a signal (message)
2. Change event: Caused by the satisfaction of a boolean
expression (continuously tested)
 when (room temperature < heating set point)
 when (room temperature < cooling set point)
3. Time event: Caused by the occurrence of an absolute time or
the elapse of a time interval
 when (date = October 28, 2010)
 after (10 seconds)
4
1.4 Event vs. state
Events: points in time
State: intervals in time
All events are ignored in a state, except those for which
behavior is explicitly prescribed. The response may include the
invocation of behavior or a change of state.
power turned on
power turned off
power turned on
time
Powered
Not powered
1.5 Transitions and conditions
Transitions: An instantaneous change from one state to another
Guard condition: A boolean expression that must be true for a
transition to occur (only checked once)
5
2 Basic State Diagram UML Notation
State diagram name
State1
do / activity
event (attribs) [condition] / effect
State2
…
event / effect
For example:
Activities for pop-up menu
right button down / display pop-up menu
Idle
right button up / erase pop-up menu
Menu
visible
cursor moved / highlight menu item
6
For example:
Do-activity for copy machine
Paper jam
do / flash warning light
For example:
Initial & final state
Chess
White’s turn
black moves
checkmate
white
moves
Black’s turn
Black wins
stalemate
Draw
stalemate
checkmate
White wins
7
3 Examples (1)
DoorOpener
Opening
depress / motor up
Closed
door open / motor off
depress / motor up
door closed / motor off
Open
depress / motor down
Closing
8
3 Examples (2)
SmartTrafficLights
North/South
timeout [cars in N/S left lanes]
May go straight
North/South
May turn left
timeout [no cars in
N/S left lanes]
timeout
timeout
timeout [no cars in
E/W left lanes]
East/West
May turn left
East/West
timeout [cars in E/W left lanes] May go straight
9
4 In-Class Exercises (1)
Draw a state diagram for a digital watch (8 minutes)
The watch has a single mode button and a single
advance button. Pressing the mode button once and
then pressing the advance button increments the
hours by 1. Each press of the advance button
increments the hour. Pressing the mode button the
second time allows advancing the minutes by 1.
Pressing the mode button a third time displays the
current time. While displaying the current time, the
advance button is ignored. Pressing the mode button
allows the user to set the hour again.
10
4 In-Class Exercises (1)
DigitalWatch
Display
Current
Advance / hours=(hours+1) mod 24
Time
Mode button
Set
Advance /
Hours
min=(min+1) mod 60
Mode button
Set
Minutes
Mode button
11
4 In-Class Exercises (2)
Draw a state diagram for an office phone when
making a call. (15 minutes)
Assume that the phone has keys for the digits 0-9,
#, and *. It can detect when the receiver is on-hook
or off-hook.
Hint: The phone is idle when the receiver is on-hook.
Based on your past experiences, you can decide the
possible states of the phone, for example, dialing,
connecting, talking, etc.
12
4 In-Class Exercises (2)
13
5 Nested State Diagram, Nested State
14
5 Nested State Diagram, Nested State (cont’d)
15
5 In-Class Exercises (3)
Draw a state diagram for an automatic transmission
(10 minutes).
The transmission can be in reverse, neutral, or
forward. If it is in forward, it can be in first, second,
or third gear. States first, second, and third are
nested states of forward. Selecting “N” in any
forward gear shifts the transmission to neutral.
Selecting “F” in neutral always shifts the
transmission to first, In any forward gear, stopping
the car always shifts the transmission to first.
16
5 In-Class Exercises (3)
17
6 Sequence Diagram
18
6 Sequence Diagram (cont’d)
19
7 Activity Diagram
20
7 Activity Diagram (cont’d)
21
Download