OBJECT-ORIENTED MODELLING
AND DESIGN
CHAPTER- 2
DYNAMIC & FUNCTIONAL MODELING
DYNAMIC MODEL
◾ Describes the aspects of a system that change
over time.
◾ It specifies and implement control aspects of a
system.
◾ Contains state diagram.
◾ State diagram is a graph whose nodes are states
and whose arcs are state transitions.
2
DYNAMIC MODELING
◾ First examine the system at a single moment of time.
◾ Then examine changes to objects and their
relationships over time.
◾ Those aspects of a system that are concerned with
time and changes with time are dynamic model, in
contrast with static or object model.
◾ Control is the aspect of a system that describes the
sequences of operations that occur in response to
external stimuli
3
CONCEPTS
◾ Events – represent external
stimuli
◾ States – values of objects
◾ State diagram
4
EVENTS AND STATES
◾ The attribute values and links held by an object are called
its state.
◾ An individual stimulus from one object to another is an
event.
◾ Response to an event depends on the state of the object
receiving it.
◾ Response can include a change of state of object or the
sending of another event to the original sender or to a
third object.
◾ The pattern of events , states and state transitions for a
given class can be abstracted and represented as a state
5
diagram.
◾ The dynamic model consists of multiple state diagrams ,
EVENTS
◾ It is something that happens at a point in time
◾ One event may logically precede or follow
another event or the two events may be
unrelated.
◾ The two events are casually unrelated are said to
be concurrent i.e. they have no effect on each
other.
◾ In modeling a system we do not establish an
ordering between concurrent events because
they can occur at any order. 6
◾ An event is a one-way transmission of
information from one object to another.
◾ In real world, all objects exist concurrently.
◾ An object sending an event to another object
may expect a reply but that reply is a
separate event under the control of the
second object which may or may not choose
to send it.
7
Light Bulb – States and Events
States:
Off – The light bulb is not glowing.
On – The light bulb is glowing
Event Description
SwitchOn() User turns on the switch.
SwitchOff() User turns off the switch.
State Transitions:
[Off] ── SwitchOn() ──> [On]
[On] ── SwitchOff() ──> [Off]
2. Mobile Phone
States:
Locked
Unlocked
Calling
InCall
Idle
Events:
EnterPassword()
MakeCall()
ReceiveCall()
EndCall()
Example Transition:
Locked ── EnterPassword() ──> Unlocked ── MakeCall() ──>
Calling
1. Fan System
States:
•Off
•on
•Low Speed
•Medium Speed
•High Speed
Events:
•TurnOn()
•SetLowSpeed()
•SetMediumSpeed()
•SetHighSpeed()
•TurnOff()
Example Transition:
Off ── TurnOn() ──> Low Speed ── SetMediumSpeed() ──>
Medium Speed └── TurnOff() ──> Off
3. Door System
States:
Closed
Open
Locked
Events:
OpenDoor()
CloseDoor()
LockDoor()
UnlockDoor()
Example Transition:
Closed ── OpenDoor() ──> Open ── CloseDoor()
──> Closed ── LockDoor() ──> Locked Locked ──
UnlockDoor() ──> Closed
◾ An event conveys information from one object
to another.
◾ Some classes of events may be simply
signals that something has occurred while other
classes convey data values i.e. attributes.
◾ Showing attributes is optional.
◾ Events include error conditions as well as
normal occurrences.
12
◾ 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.
◾ This structure is hierarchical as class structure.
◾ 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, city.
◾ The time at which an event occurs is an implicit13
attribute of all events.
Fig.1 Event classes and
attributes
14
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.
◾ It can be the historical record of executing a
system. 15
12
Fig. Scenario for phone
call
SCENARIO for ATM Machine
ATM Idle
→ Card Inserted
→ PIN Entered
→ Authenticated
→ Select Transaction
→ Transaction Selected
→ Enter Amount/Confirm
→ Processing Transaction
→ Transaction Completed
→ Eject Card or Timeout
→ Card Ejected
→ ATM Idle
◾ Each event transmits information from one object to
another.
◾ 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. 13
◾ Time increases from top to bottom.
EVENT TRACE FOR PHONE CALL
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 that affect the gross behavior
of the object
◾ A state specifies the response of the object to input
events.
◾ Response is same for all values within the same state
and may be different for values in different states.
◾ Response of an object to an event may include an
action or change of states by the object. 23
◾ A state has duration; it occupies interval of time.
◾ A state is often associated with either continuous
activity or activity that takes time to complete.
◾ An event separates two states and a state separates
two events.
◾ In defining states we ignore those attributes that
do not affect the behavior of the objects.e.g
balance is only attribute that causes state change.
So we can ignore the acc_ID and acc_type attributes
of Account object. 24
Aspect State Event
The attribute values and
An occurrence or action that may
Definition links held by an object are
trigger a state change
called its state.
Dynamic (represents an
Nature Static (describes a status)
occurrence)
Duration Exists over a period of time Happens at a single point in time
Represents the current
Role Causes transitions between states
status of the system
Remains in that state until
Persistence Temporary; does not persist
changed by an event
User clicks button, Timer expires,
Examples PowerOn, Poweroff
Data received
Representation
in State Nodes (circles or boxes) Labeled transitions (arrows)
Diagram
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.
◾ The state diagram specifies the state sequence caused
by an event sequence.
26
◾ Two categories of events: one that cause state
transitions and second that doesn’t cause state
Wrong pin
▪ State diagrams can represent one-shot life cycles or
continuous loops.
▪ Continuous state diagrams do not have any initial
states and final states. E.g. state diagram for phone
line.
▪ One-shot state diagrams represent objects with finite
lives and have initial and final states. The initial
state is entered on creation of an object; entering
the final state implies the destruction of object.
19
ONE-SHOT STATE DIAGRAM
◾ The dynamic model is collection of state
diagrams that interact with each other
via shared events.
31
◾ A condition is a Boolean function of object
values. E.g.“the temperature is below
freezing”
◾ A condition is valid over an interval of time.
E.g. “the temperature was below freezing
from 15 oct.,2013 to 15 nov.,2013”
◾ A state can be defined in terms of a condition;
conversely being in state is a condition. 32
CONDITIONS
◾ Conditions can be used as guards on
transitions.
◾ A guarded transition fires its event only if
guard condition is true.
◾ When Ram goes out in morning( event), if
the temperature is below freezing(
condition), then he puts on his gloves (next
state).
33
◾ Notation is [condition]
OPERATIONS
Activity
◾ An activity represents a process or a continuous action
that takes place while the object remains in a state.
◾ An activity is an operation that takes time to complete.
◾ An activity is associated with a state.
◾ Activities include continuous operations such as
displaying picture on TV screen as well as sequential
operations that terminate by themselves after an interval
of time, such as closing a valve or performing a
computation.
◾ A state can control a continuous activity as well as
sequential activity.
◾ Notation “do:A” within a state box indicates that activity
35
A starts on entry to the state and stops on exit.
◾ An action is an instantaneous operation.
◾ An action 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 of the event that causes
it. 38
ACTION FOR POP-UP MENU
SUMMARY OF NOTATION FOR
UNSTRUCTURED STATE DIAGRAM
28
NESTED STATE DIAGRAM
◾ State diagram can be structured to permit concise
description of complex systems.
◾ Generalization
◾ To expand nested activity
◾ Describe the activity at high level
◾ Expand the activity at a lower level by adding details.
◾ Aggregation
◾ Allows us to break the state into many components having
limited interaction among them
◾ Aggregation is equivalent to concurrency of states.
42
PROBLEMS WITH FLAT STATE DIAGRAMS
◾ Problems of state diagrams
◾ Lack expressive power
◾ Impractical for large problems
◾ These problems are particularly for flat, unstructured state diagrams
◾ Consider an object with n independent Boolean attributes that affect
control.
◾ Single flat diagram requires 2n states.
◾ If we partition state into n independent state machines , state diagram
requires only
2n states.
◾ All complex systems contain a large amount of redundancy that can be
used to simplify state diagram , provided appropriate structuring 43
mechanisms are available.
NESTING STATE DIAGRAMS
◾ An activity in state can be expanded as a
lower level state diagrams , each state
represent one step of the activity.
◾ Nested activities are one –shot state diagrams
with input and output transitions, similar to
subroutines.
44
Nested State Diagrams
● Activities in state are composite items denoting other lower
level state diagrams.
● A lower level state diagram corresponds to sequence of
lower-level states and events that are invisible in the higher
level diagram.
● Super/substates
● When one state is complex, you can include substate in it
drawn as nested rounded rectangles within the larger state.
● caution:Don’t over-use this feature easy to confuse separate
states for sub-states within one state.
Continue….
Nested states
● A state may be represented as nested substates.
● In UML, substrates are shown by nesting them in a
superstate box.
● A substrate inherits the transition of its superstate.
Nested states
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.
◾ An object in a state in the high level diagram must
be in exactly one state in the nested diagram
◾ The transitions of superstate are inherited by each 36
of its substates
EVENT GENERALIZATION
◾ Events can be organized into a generalization hierarchy with
inheritance of event attribute
◾ Providing an event hierarchy permits different level of
abstraction to be used at different places in a model
EVENT GENERALIZATION
CONCURRENCY: AGGREGATION
CONCURRENCY
◾ A state diagram for an assembly is collection of
state diagrams of each component
◾ Aggregation implies concurrency
◾ The aggregate state corresponds to the combined
state of all the component diagrams
◾ Aggregation is the “ and-relationship”
AGGREGATION AND ITS CONCURRENT STATE
DIAGRAM
AGGREGATION AND ITS CONCURRENT STATE
DIAGRAM
CONCURRENCY WITHIN AN OBJECT
◾ The object can be partitioned into subsets of attributes or
links and each subset has its own subdiagram
◾ The state of the object comprises the state from each
subdiagram
◾ The subdiagrams need not be independent; same event can
cause transition in more than one subdiagram
◾ Notation
o Composite state of object is partitioned into subdiagrams with
dotted line
o Name of the overall composite state is written in separate
region of the box, separated by solid line from concurrent
state diagrams
Microwave Oven – Object Concurrency
● Object: MicrowaveOven
This object exhibits concurrent behavior, meaning it can manage two
independent activities at the same time:
● Concurrent Subsystems
○ Heating Process
■ States:
● Idle
● Heating
● Stopped
■ Transitions:
● StartHeating → from Idle to Heating
● StopHeating → from Heating to Stopped
○ Timer Countdown
■ States:
● NoTimeSet
● CountingDown
● TimeUp
■ Transitions:
● SetTime → from NoTimeSet to CountingDown
● TimerZero → from CountingDown to TimeUp
● Concurrency Explained in This Context
● Both Heating and Timer operate concurrently inside the
MicrowaveOven object:
● When the user presses "Start", the Heating and Timer
Countdown states begin at the same time.
● The Heating stops only if:
○ The Timer reaches zero (event from timer), or
○ The user stops the microwave manually (event from user
input).
● These subsystems do not wait for each other; they
respond to different events independently.
CONCURRENCY WITHIN AN OBJECT
Object:
The main object here is “Playing rubber” — which is the overall state of the Bridge
game.
Concurrent States:
Within “Playing rubber”, there are two concurrent regions (substates):
1.N–S vulnerability
2.E–W vulnerability
These two substates exist simultaneously and independently, meaning that both
North-South and East-West pairs are progressing through their own game paths at the
same time.
State Transitions:
•N-S Line:
•Starts at Not vulnerable
•Transitions to Vulnerable when they win a game
•If they win a second game, they reach N–S wins rubber
•E-W Line:
•Starts at Not vulnerable
•Transitions to Vulnerable when they win a game
•If they win a second game, they reach E–W wins rubber
Each team's progression is tracked independently within the same enclosing object
state.
ADVANCED DYNAMIC MODELLING
CONCEPTS
◾ Entry and Exit actions
◾ Internal actions
◾ Automatic transitions
◾ Sending events
◾ Synchronization of concurrent
activities
ENTRY AND EXIT ACTIONS
◾ Actions can be associated with entering or exiting a state
◾ The entry actions are executed from outside in and the exit actions
from inside out.
◾ An entry action is shown inside the state box following the keyword
entry and a “/”character.
◾ An exit action is shown inside the state box following the
keyword exit and a “/”character.
◾ If multiple operations are specified on a state , they are performed in
the following order
1. Actions on incoming transition
2. Entry actions
3. do activities
4. Exit actions
5. Actions on outgoing transition
◾ if do activity is interrupted , the exit action is nevertheless performed.
ENTRY AND EXIT ACTIONS
ENTRY AND EXIT ACTIONS
➤ State: Closed
•Entry Action: motor off
•Meaning: The motor stops running when the door is fully closed.
➤ State: Opening
•Entry Action: motor up
•Meaning: The motor starts moving the door upward to open it.
➤ State: Open
•Entry Action: motor off
•Meaning: The motor stops running when the door is fully open.
➤ State: Closing
•Entry Action: motor down
•Meaning: The motor runs in the opposite direction to close the door.
INTERNAL ACTIONS
◾ An event can cause an action to be performed without causing a state
change
◾ The event name is written inside state box followed by “/” and name of
action
◾ When such event occurs, its action is executed but not the entry or exit
actions for the state.
◾ event / monitor temperature, it will monitor temparature and it will not
change state
AUTOMATIC TRANSITION
◾ An arrow without an event name indicates an automatic
transition .
◾ Automatic transition fires when the activity associated 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.
◾ If state has one or more automatic transitions, but none of the
guard conditions are satisfied then the state remains active
until one of the conditions is satisfied or until an event
causes another transition to fire.
SENDING EVENTS
◾ An object can perform action of sending an event to another
object.
◾ A system of objects interacts by events.
◾ The action “send E(attributes)” sends event E with the given
attributes to the object or objects that receive it.
◾ An event can be directed to a single object or a group of
objects. Any and all objects can accept it concurrently.
◾ 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. Unwanted race
conditions should be avoided.
◾ When an object interacts with an external object, such as person
or device, sending an event is often indistinguishable from an
SYNCHRONIZATION OF CONCURRENT
ACTIVITIES
◾ Sometimes an object state 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.
◾ The target state occurs after both events happen in any order.