You are on page 1of 20

Interaction Diagrams

The term Interaction, it is clear that the diagram


is used to describe some type of interactions
among the different elements in the model.
This interaction is a part of dynamic behavior of
the system.
This interactive behavior is represented in UML
by two diagrams known as Sequence
diagram and Collaboration diagram. The
basic purpose of both the diagrams is similar.
Sequence diagram emphasizes on time
sequence of messages and collaboration
diagram emphasizes on the structural
organization of the objects that send and
receive messages.
INTERACTION DIAGRAM is used in UML to
establish communication between objects.
Purpose of Interaction Diagrams
The purpose of interaction diagrams is to
visualize the interactive behavior of the system.
Visualizing the interaction is a difficult task.
Hence, the solution is to use different types of
models to capture the different aspects of the
interaction.
Sequence and collaboration diagrams are used
to capture the dynamic nature but from a
different angle.
The purpose of interaction diagram is −
 To capture the dynamic behavior of a
system.
 To describe the message flow in the
system.
 To describe the structural organization of

the objects.
 To describe the interaction among objects.

How to Draw an Interaction Diagram?


So to capture the dynamic aspect, we need to
understand what a dynamic aspect is and how
it is visualized.
Dynamic aspect can be defined as the
snapshot of the running system at a particular
moment.
We have two types of interaction diagrams
in UML.
 One is the sequence diagram
 Other is the collaboration diagram.
The sequence diagram captures the time
sequence of the message flow from one object
to another
The collaboration diagram describes the
organization of objects in a system taking part
in the message flow.
Following things are to be identified clearly
before drawing the interaction diagram
 Objects taking part in the interaction.

 Message flows among the objects.

 The sequence in which the messages are

flowing.
 Object organization.

Following are two interaction diagrams


modeling the order management system. The
first diagram is a sequence diagram and the
second is a collaboration diagram
The Sequence Diagram
The sequence diagram has four objects
(Customer, Order, SpecialOrder and
NormalOrder).
The following diagram shows the message
sequence for SpecialOrder object and the
same can be used in case
of NormalOrder object. It is important to
understand the time sequence of message
flows. The message flow is nothing but a
method call of an object.
The first call is sendOrder () which is a method
of Order object. The next call is confirm
() which is a method of SpecialOrder object
and the last call is Dispatch () which is a
method of SpecialOrder object.
The following diagram mainly describes the
method calls from one object to another,

(P.T.O)
And this is also the actual scenario when the
system is running.

The Collaboration Diagram


 The second interaction diagram is the
collaboration diagram. It shows the object
organization as seen in the following diagram.
In the collaboration diagram, the method call
sequence is indicated by some numbering
technique.
 The number indicates how the methods are
called one after another. We have taken the
same order management system to describe
the collaboration diagram.
 Method calls are similar to that of a sequence
diagram. However, difference being the
sequence diagram does not describe the object
organization, whereas the collaboration
diagram shows the object organization.
 To choose between these two diagrams,
emphasis is placed on the type of requirement.
If the time sequence is important, then the
sequence diagram is used. If organization is
required, then collaboration diagram is used.

Where to Use Interaction Diagrams?


The main purpose of both the diagrams is
similar as they are used to capture the dynamic
behavior of a system. However, the specific
purpose is more important to clarify and
understand.
Sequence diagrams are used to capture the
order of messages flowing from one object to
another.
Collaboration diagrams are used to describe
the structural organization of the objects taking
part in the interaction.
 A single diagram is not sufficient to describe
the dynamic aspect of an entire system, so a
set of diagrams are used to capture it as a
whole.
Interaction diagrams are used when we want to
understand the message flow and the
structural organization.
Message flow means the sequence of control
flow from one object to another. Structural
organization means the visual organization of
the elements in a system.
Interaction diagrams can be used −
 To model the flow of control by time
sequence.
 To model the flow of control by structural

organizations.
 For forward engineering.
 For reverse engineering.

No
tation of an interaction diagram
Lifeline
A lifeline represents a single participant in an
interaction. It describes how an instance of a
specific classifier participates in the interaction.
A lifeline represents a role that an instance of
the classifier may play in the interaction.
Following are various attributes of a lifeline,
1. Name
1. It is used to refer the lifeline within a
specific interaction.
2. A name of a lifeline is optional.
2. Type
1. It is the name of a classifier of which
the lifeline represents an instance.
3. Selector
1. It is a Boolean condition which is
used to select a particular instance that
satisfies the requirement.
2. Selector attribute is also optional.
The notation of lifeline is explained in the
notation section.
Messages
A message is a specific type of communication
between two lifelines in an interaction. A
message involves following activities,
1. A call message which is used to call an
operation.
2. A message to create an instance.
3. A message to destroy an instance.
4. For sending a signal.
When a lifeline receives a call message, it acts
as a request to invoke an operation that has a
similar signature as specified in the message.
When a lifeline is executing a message, it has a
focus of control. As the interaction progresses
over time, the focus of control moves between
various lifelines. This movement is called a flow
of control.
Following are the messages used in an
interaction diagram:

Message Meaning
Name

Synchronous The sender of a message


message keeps waiting for the receiver to
return control from the
message execution.

Asynchronou The sender does not wait for a


s message return from the receiver;
instead, it continues the
execution of a next message.

Return The receiver of an earlier


message message returns the focus of
control to the sender.

Object The sender creates an instance


creation of a classifier.

Object The sender destroys the


destruction created instance.

Found The sender of the message is


message outside the scope of interaction.

Lost message The message never reaches


the destination, and it is lost in
the interaction.

State invariants and constraints


When an instance or a lifeline receives a
message, it can cause it to change the state. A
state is a condition or a situation during a
lifetime of an object at which it satisfies some
constraint, performs some operations, and
waits for some event.
In interaction diagram, not all messages cause
to change the state of an instance. Some
messages do not the values of some attribute.
It has no side effects on the state of an object.
Operator
An operator specifies an operation on how the
operands are going to be executed.
The operators in UML supports operations on
data in the form of branching as well as an
iteration. Various operators can be used to
ensure the use of iteration and branching in the
UML model. The opt and alt operators are used
for branching operations.
The loop operator is used to ensure the
iteration operations in which a condition is
executed repeatedly until the satisfying result is
produced. Break operator is used inside the
loop or iteration operations. It ensures that the
loop is terminated whenever a break operator is
encountered.
If a break condition is not specified, then the
loop executes the infinite number of times,
which results in crashing the program.
Following are the operators used in an
interaction diagram:

Operator Name Meaning

Opt Option An operand is executed if the co


true. e.g., If else

Alt Alternative The operand, whose condition is


executed. e.g., switch

Loop Loop It is used to loop an instruction fo


specified period.

Break Break It breaks the loop if a condition is


false, and the next instruction is

Ref Reference It is used to refer to another inter

Par Parallel All operands are executed in par

Iteration
In an interaction diagram, we can also show
iteration using an iteration expression. An
iteration expression consists of an iteration
specifier and an optional iteration clause. There
is no pre-specified syntax for UML iteration.
In iteration to show that messages are being
sent in parallel, parallel iteration specifier is
used. A parallel iteration specifier is denoted by
*//. Iteration in UML is achieved by using the
loop operator.
Branching
In an interaction diagram, we can represent
branching by adding guard conditions to the
messages. Guard conditions are used to check
if a message can be sent forward or not. A
message is sent forward only when its guard
condition is true. A message can have multiple
guard conditions, or multiple messages can
have the same guard condition. Branching in
UML is achieved with the help of alt and opt,
operators.
These are some of the most
important terminologies used in UML
interaction diagram.
Sequence diagram example
The following sequence diagram example
represents McDonald's ordering

Sequence diagram of Mcdonald's ordering system


Benefits of a Sequence Diagram
 Sequence diagrams are used to explore any
real application or a system.
 Sequence diagrams are used to represent
message flow from one object to another
object.
 Sequence diagrams are easier to maintain.
 Sequence diagrams are easier to generate.
 Sequence diagrams can be easily updated
according to the changes within a system.
 Sequence diagram allows reverse as well
as forward engineering.
Drawbacks of a sequence diagram
 Sequence diagrams can become complex
when too many lifelines are involved in the
system.
 If the order of message sequence is
changed, then incorrect results are
produced.
 Each sequence needs to be represented
using different message notation, which can
be a little complex.
 The type of message decides the type of
sequence inside the diagram.
Benefits of Collaboration Diagram
 It is also called as a communication
diagram.
 It emphasizes the structural aspects of an
interaction diagram - how lifeline connects.
 Its syntax is similar to that of sequence
diagram except that lifeline don't have tails.
 Messages passed over sequencing is
indicated by numbering each message
hierarchically.
 Compared to the sequence diagram
communication diagram is semantically
weak.
 Object diagrams are special case of
communication diagram.
 It allows you to focus on the elements rather
than focusing on the message flow as
described in the sequence diagram.
 Sequence diagrams can be easily
converted into a collaboration diagram as
collaboration diagrams are not very
expressive.
 While modeling collaboration diagrams w.r.t
sequence diagrams, some information may
be lost.
The above collaboration diagram notation
contains lifelines along with connectors, self-
loops, forward, and reverse messages used in
a collaboration diagram.
Drawbacks of a Collaboration Diagram
 Collaboration diagrams can become
complex when too many objects are present
within the system.
 It is hard to explore each object inside the
system.
 Collaboration diagrams are time consuming.
 The object is destroyed after the termination
of a program.
 The state of an object changes
momentarily, which makes it difficult to keep
track of every single change the occurs
within an object of a system.
Collaboration diagram Example
Following diagram represents the sequencing
over student management system:
Collaboration diagram for student management
system
The above collaboration diagram represents a
student information management system. The
flow of communication in the above diagram is
given by,
1. A student requests a login through the
login system.
2. An authentication mechanism of
software checks the request.
3. If a student entry exists in the database,
then the access is allowed; otherwise, an
error is returned.

What is Timing diagram?


TIMING DIAGRAM is a waveform or a graph
that is used to describe the state of a lifeline at
any instance of time. It is used to denote the
transformation of an object from one form into
another form. Timing diagram does not contain
notations as required in the sequence and
collaboration diagram. The flow between the
software program at various instances of time is
represented using a waveform.

You might also like