8/20/2012
Introduction
Object-Oriented Analysis and Design
Unit-Ic Dynamic Modeling
We examine changes to the objects and their relationships over time. Those aspects of a system with time and changes are called dynamic model Control is the aspect of the system that describes the sequences of operations that occur in response to external stimuli , without consideration of:
What the operation do What they operate on How they are implemented
The major dynamic modeling concepts are:
Events :- represent external stimuli States :- represent values of objects State diagrams :- graphical representation of finite state machine
L.GOWRI,CA
L.GOWRI,CA
Events and States
The attribute values and links held by an object are called its state. Over time, the objects stimulate each other, resulting in a series of changes to their states. An individual stimulus from one object to another is an event. The response of an event depends on the state of the object receiving it, it can include
a change of state or the sending of another event to the original sender or to a third object.
L.GOWRI,CA 3
Events
An event is something that happens at appoint in time. An event has no duration.
One event may logically precede or follow another, or the two events may be unrelated.
Two events that are casually unrelated are said to be concurrent; they have no effect on each other. Concurrent events can occur in any order. An event is a one way transmission of information from one object to another. 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.
L.GOWRI,CA 4
8/20/2012
Event classes
An event conveys information from one object to another (either signals or data values) The data values conveyed by events are its attributes, like data values held by its objects. Attributes are shown in the parentheses after the event class name. Events include error conditions as well as normal occurrences. Eg :-transaction aborted , time out
L.GOWRI,CA 5
Event classes
L.GOWRI,CA
Scenarios
A scenario is a sequence of events that occurs during one particular execution of system. The scope of a scenario can vary It may include all events in the system or it may include only certain events Each event transmits information from one object to another Ex: dial tone begins transmits a signal from the phone line to the caller
L.GOWRI,CA 7
Scenario for telephone system
L.GOWRI,CA
8/20/2012
Event Trace
After writing a scenario is to identify the sender and receiver objects of each end The sequence of events and the objects exchanging events can both be shown in an augmented scenario called an event trace diagram This diagram shows each object as a vertical line and each event as a horizontal arrow from the sender object to the receiver object
L.GOWRI,CA 9
Event Trace
L.GOWRI,CA
10
States
A states is an abstraction of the attribute values and links of an object State has duration . It occupies an interval of time State is often associated with a continuous activity. Ex. Telephone ringing A state separates two events and event separates two states
L.GOWRI,CA 11
Difference between states and events
States 1. Represent values of object 2. The attribute values and links held by an object 3. A state has duration.it occupies an interval of time 4. State separates two events Events 1. Represent external stimuli 2. An individual stimulus from one object to another 3. An event has no duration. It happens at a point of time 4. An event separates two states
12
L.GOWRI,CA
8/20/2012
State Diagrams
A state diagram 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 transitions A state diagram is a graph whose nodes are states and whose directed arcs are transitions labeled by and event names
L.GOWRI,CA 13
State Diagrams
A state is drawn as a rounded box containing an optional name A transition is drawn as a arrow from the receiving state to the target state The label on the arrow is the name of the event causing the transition State diagram specifies the state sequence caused by an event sequence. A sequence of events corresponds to a path through the graph
L.GOWRI,CA 14
State Diagrams
If an object is in a state and an event labeling one of its transition occurs, the objects enters the state on the target end of the transition. The transition is said to fire.
If more than one transition leaves a state then the first event to occur causes the corresponding transition to fire. If an event occurs that no transition leaving the current state, then the event is ignored.
State diagram( continuous loop) for phone line
State diagram contains sequences associated with normal call as well as abnormal call ( time out while dialing , getting busy line) States can represent
continuous loops one shot life cycles or
L.GOWRI,CA 15 L.GOWRI,CA 16
8/20/2012
One-shot state diagram
It represents objects with finite lives It has initial and final states The initial state is entered on creation of an object An initial state is shown by a solid circle The circle can be labeled to indicate different initial conditions Final state implies destruction of the object The final state shown by a bulls eye. It distinguished from initial state
L.GOWRI,CA 17
State diagram( One shot) for chess game
L.GOWRI,CA
18
Conditions
A condition is a Boolean function of object values It is valid over interval of time A state can be defined in terms of a condition Conditions can be used as guards on transitions A guards transitions fires when its event occurs , but only if the guard condition is true A condition is listed within square brackets [] after an event name
L.GOWRI,CA 19
Conditions
For example
a person goes out in the morning (event), if the temperature is below freezing (condition) , then put on your gloves(next state).
L.GOWRI,CA
20
8/20/2012
Conditions
Operations
It shows how events trigger operations There are two types
[not attended] result
[value < 50] fail
Activity Action
[(value >= 50) & (value <=100)] pass
L.GOWRI,CA
21
L.GOWRI,CA
22
Activity
An activity is an operation that takes time to complete. An activity is associated with a state. Activities include continuous as well as sequential events. A state may control a continuous activity that persists until an event terminates it by calling a transition from the state. Notation : do: activity name within state box
It indicates that activity starts an entry to the state and stops on exit.
Activity
state 1 do:activity1 do:activity2
event name
state 2 do:activity1 do:activity2
If an event causes a transition from the state before the activity is complete, it terminates prematurely.
L.GOWRI,CA 23 L.GOWRI,CA 24
8/20/2012
Actions
An action is an instantaneous operation. It is associated with an event Actions can also represent internal control operations, such as setting attributes or generating other events. Notation : (/ on transition) for action and the name (or) description of the action following the name of the event.
L.GOWRI,CA 25
Actions
right button down/display pop up menu idel right button up/erase pop up menu Menu visible
Cursor moved/highlight menu item
L.GOWRI,CA
26
Actions
Activity
Difference between
Action
1. can be performed within a state. 2. can be continuous. 3. can be sequential. 4. takes time.
1. can be performed within a state or during a transition. 2. can not be interrupted. 3. is atomic. 4. May be take time.
L.GOWRI,CA
27
L.GOWRI,CA
28
8/20/2012
Phone Line Example
on hook
State diagrams
Disadvantages
Quite complex when no of states is increase Difficult to specify concurrency
Idle
off hook
on hook time out Time out time out invalid number Recorded valid number
message
do: play message
on hook
Dial tone
do: sound dial tone
digit (n)
digit (n)
Dialing
Busy tone
do: sound busy tone
busy
Connecting
on hook on hook on hook / disconnect line on hook
do: find connection
routed
message done
Ringing Connected Disconnected
L.GOWRI,CA
called phone answers / connect line called phone hangs up / disconnect line
L.GOWRI,CA 30
Nested state diagrams
State diagrams can be structured to permit concise descriptions of complex systems. It allows generalization and aggregation Generalization is equivalent to expanding nested activities.
It allows an activity to be described at a high level then expanded at a lower level by adding details
Problems with flat state diagram
State diagrams lack expressive power and are impractical for large problems. These problems are true of flat, unstructured state diagrams. For example: an object with n independent Boolean attributes that affect control and flat state diagram would requires 2n states. The n2 transitions are needed to connect every state to every other state. if may be reformulated then transitions can be reduced as n
L.GOWRI,CA 32
Aggregation allows with limited interaction among them
It is equivalent to concurrency of states
L.GOWRI,CA 31
8/20/2012
Nested State Diagrams
An activity in a state can be expanded as a lower level state diagram, each state representing one step of the activity. Nested activities are one shot diagrams with input and output transitions, similar to subroutines.
High level vending machine model
L.GOWRI,CA
33
L.GOWRI,CA
34
Nesting state diagrams
In the Fig I
The event coins in (amount) is written within the collecting money state; this indicates a transition that remains within a single state Also, the transition from the unnamed state containing do: dispense item to state idle has no event label The lack of event label indicates that the transition fires automatically when the activity in the state is complete
L.GOWRI,CA 35
Nesting state diagrams
The following figure shows a sub diagram for the dispense item activity of the Fig - i
Events can also be expanded into subordinate state diagrams The following figure shows the select item event from Fig - i
L.GOWRI,CA
36
8/20/2012
State generalization
States may have sub states that inherit the transitions of their super states A super state is drawn as a large rounded box enclosing all of its sub states Sub states in turn can enclose further sub states The rounded boxes representing various states are nested, and called as contours
Event Generalization
Events can be organized into generalization hierarchy with inheritance of event attributes. An event hierarchy permits different levels of abstraction to be used at different places in a model.
Fig state diagram of car transmission with generalization
L.GOWRI,CA
37
L.GOWRI,CA
38
Concurrency
1. Aggregation Concurrency A dynamic model describes a set of concurrent objects. A state of an entire system cant be represented by a single state in a single object. It is the product of the states of all objects in it. A state diagram for an assembly is a collection of state diagram, one for each component. By using aggregation we can represent concurrency. Aggregate state corresponds to combined state of all component diagrams.
L.GOWRI,CA 39 L.GOWRI,CA 40
10
8/20/2012
Concurrency
2. Concurrency within an object Concurrency within a single composite state of an object is shown by partitioning the composite state into sub diagrams with dotted lines.
Payment authorization
L.GOWRI,CA
41
L.GOWRI,CA
42
Advanced Dynamic modeling concepts
Entry and Exit actions Internal Actions Automatic Transition Sending events Synchronization of concurrent activities
Entry and Exit actions
Actions can be associated with entering or exiting a state Entry Actions An entry action is shown inside the state box following the keyword entry and a / character. Whenever the state is entered, by any incoming transition, the entry action is performed
43 L.GOWRI,CA 44
L.GOWRI,CA
11
8/20/2012
Entry and Exit actions
Exit Actions An exit action is shown inside the state box following the keyword exit and / character Whenever the state is exited, by any outgoing transition, the exit action is performed first. If multiple operations are specified on a state, they are performed in the following order:
action on the incoming transition will be executed first, the entry action, activity within the state, exit action and finally the action on the outgoing action
Actions on transitions
opening depress/motor up Door open/motor off depress/motor up closed open
Door closed/motor off closing
depress/motor down
L.GOWRI,CA
45
L.GOWRI,CA
46
Actions on entry to states
Opening
entry/motor up
Internal actions
An event can cause an action to be performed without causing a state change The event name is written inside the state box, followed by a / and the name of the action Keywords entry, exit, and do are reserved words within the state box Self transition causes the exit and entry actions for the state to be executed Therefore there is a difference between an internal action and self transition
State
depress Door open Closed
entry/motor off
depress Open
entry/motor off
Door closed Closing
entry/motor down
depress
Do : activity1 Entry / action2 Exit / action3 Event / action4
47 L.GOWRI,CA 48
L.GOWRI,CA
12
8/20/2012
Automatic transition
A state performs a sequential activity. An arrow without an event name indicates an automatic transition that fires when the activity associates with the source state is completed. If there is no activity, the unlabeled transitions fires as soon as the state is entered. Such transitions are called as lambda transitions.
L.GOWRI,CA 49
Sending events
An object can perform action of sending an event to another object. A system interacts by events. An event can be directed to a single or a group of objects. If a state can accept events from more than one object, the order in which concurrent events are received may affect final state. This is called a race condition (two events being received simultaneously ) Unwanted race conditions should be avoided.
L.GOWRI,CA 50
Sending an event from one object to another
State1 Do : activity1 Entry / action2 Exit / action3 Event / action4 State2 Event1(attri1)[cond]/action1 Do : activity1 Entry / action2 Exit / action3 Event / action4 Event2(attri2)
Synchronization of concurrent activities
Sometimes one object must perform two (or more) activities concurrently The internal steps of the activities are not synchronized, but both activities must be completed before the object can progress to its next state Concurrent activities within a single composite activity are shown by partitioning a state into regions with dotted lines Splitting of control into concurrent parts is shown by an arrow that forks Merging of concurrent control is shown by an arrow with a forked tail The following figure shows a concurrent state diagram for the emitting activity
Object class
L.GOWRI,CA
51
L.GOWRI,CA
52
13