CS504-Software Engineering – I VU
Lecture No. 209
Interaction Diagrams – depicting the dynamic behaviour of
the system
A series of diagrams can be used to describe the dynamic behavior of an object-oriented
system. This is done in terms of a set of messages exchanged among a set of objects
within a context to accomplish a purpose. This is often used to model the way a use case
is realized through a sequence of messages between objects.
The purpose of Interaction diagrams is to:
Model interactions between objects
Assist in understanding how a system (a use case) actually works
Verify that a use case description can be supported by the existing classes
Identify responsibilities/operations and assign them to classes
UML provides two different mechanisms to document the dynamic behaviour of the
system. These are sequence diagrams which provide a time-based view and
Collaboration Diagrams which provide an organization-based view of the system’s
dynamics.
The Sequence Diagram
Let us first look at Sequence Diagrams. These diagrams illustrate how objects interacts
with each other and emphasize time ordering of messages by showing object interactions
arranged in time sequence. These can be used to model simple sequential flow,
branching, iteration, recursion and concurrency. The focus of sequence diagrams is on
objects (and classes) and message exchanges among them to carry out the scenarios
functionality. The objects are organized in a horizontal line and the events in a vertical
time line.
The Notation
Following diagram illustrates the notation used for drawing sequence diagrams.
: Professor Math 101 - Section
CourseManager 1 : CourseOffering
Add professor (Professor)
_____________________________________________________________________
© Copyright Virtual University of Pakistan
Lifeline Message
CS504-Software Engineering – I VU
The boxes denote objects (or classes), the solid lines depict messages being sent from one
object to the other in the direction of the arrow, and the dotted lines are called life-lines of
objects. The life line represents the object’s life during interaction. We will discuss this in
more detail later.
These concepts are further elaborated with the help of the following sequence diagram.
X-Axis (objects)
member: book:Book :Book
LibraryMember Copy
borrow(book) Object
ok = mayBorrow() Life
message
Y-Axis (time)
Line
Activation
[ok] borrow(member) setTaken(member) box
condition
As shown above, in a sequence diagram, objects (and classes) are arranged on the X-Axis
(horizontally) while time is shown on the Y-Axis (vertically). The boxes on the life-line
are called activation boxes and show for how long a particular message will be active,
from its start to finish. We can also show if a particular condition needs to occur before a
message is invoked simply by putting the condition in a box before the message. For
example, object member:LibraryMember sends a message to object book:book if the
value of ok is true.
The syntax used for naming objects in a sequence diagram is as follows:
syntax: [instanceName][:className]
Name classes consistently with your class diagram (same classes).
Include instance names when objects are referred to in messages or when several
objects of the same type exist in the diagram.
An interaction between two objects is performed as a message sent from one object to
another. It is most often implemented by a simple operation call. It can however be an
_____________________________________________________________________
© Copyright Virtual University of Pakistan
CS504-Software Engineering – I VU
actual message sent through some communication mechanism, either over the network or
internally on a computer.
If object obj sends a message to another object obj an association must exist between
1 2
those two objects. There has to be some kind of structural dependency. It can either be
that obj2 is in the global scope of obj1, or obj2 is in the local scope of obj1 (method
argument), or obj and obj are the same object.
1 2
A message is represented by an arrow between the life lines of two objects. Self calls are
also allowed. These are the messages that an object sends to itself. This notation allows
self calls. In the above example, object member:LibraryMember sends itself the
mayBorrow message. A message is labeled at minimum with the message name.
Arguments and control information (conditions, iteration) may also be included. It is
preferred to use a brief textual description whenever an actor is the source or the target of
a message.
The time required by the receiver object to process the message is denoted by an
activation-box.
Lecture No. 19
9