UNIT 2.
Dynamic Modeling
Prepared By: Mr. V. D. Chougule 1
Contents
• Events and States
• Operations
• Nested state diagrams
• Concurrency
• Advanced dynamic modeling concepts
• Relation of object and dynamic models
Prepared By: Mr. V. D. Chougule 2
Dynamic Modeling
• Those aspects of a system that are concerned with
time and changes are dynamic model, in contrast with
static or object model.
Prepared By: Mr. V. D. Chougule 3
Events & States
• Events – Represent external stimuli/ Something that
happen in time
• States – values of objects
Prepared By: Mr. V. D. Chougule 4
Events
• Event is something that happens at a point in time
• One event may logically precede or follow another or
the two events may be unrelated.
• The two events are casually related.
• An event is a one-way transmission of information
from one object to another.
Prepared By: Mr. V. D. Chougule 5
Events
• Every event is a unique occurrence, but we group
them into event classes and give each event class a
name to indicate common structure and behavior.
• E.g. flight 123 departs from Delhi and flight 321
departs from Rome are instances of event class
airplane flight departs having attributes airline flight
no. and city.
Prepared By: Mr. V. D. Chougule 6
Airplane flight departs (airline, flight#, city)
Mouse button pushed (button, location)
Input string entered (text)
Digit dialed (digit)
Figure 2.1Event classes and attributes
Prepared By: Mr. V. D. Chougule 7
Scenarios and event traces
• A scenario is a sequence of events that occurs during
one particular execution of a system.
• The scope of a scenario can vary; it may include all
events in the system or it may include only those
events generated by certain objects in the system.
Prepared By: Mr. V. D. Chougule 8
Caller lifts receiver
Dial tone begins
Caller dials digit (5)
Dial tone ends
Caller dials digit (5)
Caller dials digit (5)
Caller dials digit (1)
Caller dials digit (2)
Caller dials digit (3)
Caller dials digit (4)
Called phone begins ringing
Ringing tone appears in calling phone
Called party answers
Called phone stops ringing
Ringing tone disappears in calling phone
Phones are connected
Called party hangs up
Phones are disconnected
Caller hangs up
Figure 2.2 Scenario for
Prepared By: Mr. V. D.phone
Chougule call 9
Event Trace
• The next step after writing scenario is to identify the
sender and receiver objects of each event.
• The sequence of events and the objects exchanging
events are shown in event trace diagram.
• This diagram shows each object as a vertical line and
each event as a horizontal arrow from the sender to
receiver objects.
• Time increases from top to bottom.
• Sequences of events are shown not their exact timing.
Prepared By: Mr. V. D. Chougule 10
Caller phone line Callee
Caller lifts receiver
Dial tone begins
Caller dials digit (5)
Dial tone ends
Caller dials digit (5)
Caller dials digit (4)
Caller dials digit (3)
Caller dials digit (2)
Caller dials digit (1)
Called phone begins ringing phone rings
answer phone
ringing stops ringing stops
phones are connected phones connected
Callee hangs up
disconnected disconnected
Caller hangs up
Figure 2.3 Event trace for phone call
Prepared By: Mr. V. D. Chougule 11
States
• It is an abstraction of the attribute values and links of an
object.
• Set of values are grouped together into a state according to
properties.
• A state specifies the response of the object to input events.
• Response of an object to an event may include an action or
change of states by the object.
• A state has duration.
• An event separates two states and a state separates two events.
Prepared By: Mr. V. D. Chougule 12
State diagram
• It relates events and states.
• When an event is received, the next state depends on the
current state as well as the event; a change of state caused by
an event is called a transition.
• State diagram is a graph whose nodes are states and whose
directed arcs are transitions labeled by event names.
Prepared By: Mr. V. D. Chougule 13
On-hook
On-hook
idle
Off-hook
Dial tone Timed- out
Digit(n)
dialing Recorded message
Invalid no
Num busy valid
Busy tone
connecting
Fast busy tone Trunk busy routed
ringing
Called phone answers
connected
Called phone hangs up
disconnected
Figure 2.4 State diagram
Preparedfor phone
By: Mr. line
V. D. Chougule 14
Figure 2.5 One-shot state diagram for chess game
Prepared By: Mr. V. D. Chougule 15
State diagram
• A state diagram describes the behavior of a single
class.
• Since all instances of a class have same behavior they
all share the same state diagram as they all share the
same class features.
• But as each object has its own attribute values so each
object has its own state.
• Each object is independent of the other objects.
Prepared By: Mr. V. D. Chougule 16
Conditions
• A condition is a Boolean function of object values.
• When Ram goes out in morning (event), if the temperature is
below freezing (condition), then he puts on his gloves (next
state).
• Condition can be used as guards on transitions.
• A guarded transition fires when its event occurs, but only if
guarded condition is true.
• Notation is [condition]
Prepared By: Mr. V. D. Chougule 17
Figure 2.6 State diagram with guarded transitions
Prepared By: Mr. V. D. Chougule 18
Operations
• Controlling operations
• An activity is an operation that takes time to complete.
• An activity is associated with a state.
• Notation “do:A” within a state box indicates that activity A
starts on entry to the state and stops on exit.
• An action is an instantaneous operation.
• An operation is associated with an event.
• An action represents an operation whose duration is
insignificant compared to the state diagram e.g. disconnect
phone line might be an action in response to an on_hook event
for phone line.
• Actions can also represent internal control operations such as
setting attributes or generating other events.
• The notation for an action is (“/”) and the name of action,
following the name ofPrepared
the event that
By: Mr. V. D. causes it.
Chougule 19
Right button down/display menu
idle Menu visible
Right button up/erase menu
Cursor moved/highlight menu item
Action for pop-up menu
Prepared By: Mr. V. D. Chougule 20
• Summary of notation for state diagrams with operations
State1 Event1 (attributes)[condition1]/action1 State2
do:activity1 do:activity1
Summary of notation for state diagrams
Prepared By: Mr. V. D. Chougule 21
State diagram for phone line
Prepared By: Mr. V. D. Chougule 22
Nested State Diagrams
• An activity in state can be expanded as lower
level state diagram.
• Each state representing one step of the activity.
• Nested activities are one shot state diagrams
with i/p and o/p transitions.
• e.g. top level model for vending machine, an
activity dispense item and an event
select(item) that expanded in more detail in
nested state diagram.
Prepared By: Mr. V. D. Chougule 23
Prepared By: Mr. V. D. Chougule 24
Prepared By: Mr. V. D. Chougule 25
Vending Machine model
Prepared By: Mr. V. D. Chougule 26
Dispense item activity of vending machine
Select item transition of vending machine
Prepared By: Mr. V. D. Chougule 27
State generalization
• A nested state diagram is a form of generalization on
states.
• Generalization is “or-relation”.
• States may have sub states that inherit the transitions
of their super states just as classes have subclasses
that inherit the attributes and operations of their super
classes.
Prepared By: Mr. V. D. Chougule 28
State diagram of car transmission with generalization
Transmission Push R
Neutral Reverse
Push N
Push N
Push F
Forward
Stop upshift upshift
First Second Third
downshift downshift
Prepared By: Mr. V. D. Chougule 29
Event Generalization
• Events can be organized into generalization hierarchy
with inheritance of attribute values
• Ex. Hierarchy/Tree of input events for a workstation
Prepared By: Mr. V. D. Chougule 30
Concurrency
• Aggregation concurrency
• Dynamic model describes set of concurrent objects, with its
own state and state diagram .
• Objects in the system are inherently concurrent and can change
state independently.
• Aggregation implies concurrency.
• Concurrency within an object
• Concurrency within object comes when object partitioned into
subsets of attributes or links, each of which has its own
subdiagram
Prepared By: Mr. V. D. Chougule 31
Aggregation and its concurrent state diagram
Car
Ignition Transmission Brake Accelerator
Ignition
Turn key to
start[Transmission
in Neutral] Released Key
off starting on
Turn key off
Prepared By: Mr. V. D. Chougule 32
State diagram of car transmission with generalization
Transmission Push R
Neutral Reverse
Push N
Push N
Push F
Forward
Stop upshift upshift
First Second Third
downshift downshift
Prepared By: Mr. V. D. Chougule 33
Accelerator Brake
press press
Off On Off On
Release Release
Prepared By: Mr. V. D. Chougule 34
Advanced Dynamic Modeling Concepts
• Entry and Exit Actions:-
-to showing actions on transition , actions can be
associated with entering or exiting state.
-there is no difference in expensive power between
the two notations, but frequently all transition into
state perform the same action.
Prepared By: Mr. V. D. Chougule 35
Actions on transitions
Prepared By: Mr. V. D. Chougule 36
Continued
-an entry action is inside the state box following
keyword entry and a „/‟ character.
-state is entered by any incoming transition the entry
action is performed.
-an entry action is equivalent to attaching the action
to every incoming transition.
Prepared By: Mr. V. D. Chougule 37
Actions on entry to states
Prepared By: Mr. V. D. Chougule 38
• Internal Actions
• An event can causes an action to be performed
without causing a state change.
• Event name is written inside the state box
followed by “/” & name of the action.
• When such event occurs it‟s action is executed but
not the entry or exit action for the state.
Prepared By: Mr. V. D. Chougule 39
Summary of extended notation for state diagram
Prepared By: Mr. V. D. Chougule 40
• Automatic transition
• An arrow without an event name indicates an
automatic transition that fires when the activity
associated with source state is completed.
• Sending events
• An object can perform the action of sending an
event to another object. A system of objects
interacts by exchanging events.
Prepared By: Mr. V. D. Chougule 41
Synchronization of concurrent activities
• Sometime one object must perform two or more
activities concurrently.
• Internal step of activity are not synchronized but both
activities must be completes before the object can
progress to it‟s next state.
• e.g. Use splitting control into concurrent activities
and later merging control.
Prepared By: Mr. V. D. Chougule 42
Synchronization of control
Prepared By: Mr. V. D. Chougule 43