6 UML Interaction Diagram
6 UML Interaction Diagram
Interaction Diagram is used in UML to establish communication between objects. It does not
manipulate the data associated with the particular communication path.
Interaction diagrams mostly focus on message passing and how these messages make up one
functionality of a system. Interaction diagrams are designed to display how the objects will
realize the particular requirements of a system. The critical component in an interaction diagram
is lifeline and messages.
The details of interaction can be shown using several notations such as sequence diagram, timing
diagram and communication/collaboration diagram.
Important terminology
An interaction diagram contains lifelines, messages, operators, state invariants and constraints.
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.
Lifeline Notation
A lifeline with a boundary element indicates a system boundary/ software element in a system;
for example, user interface screens, database gateways or menus that users interact with, are
boundaries.
And a lifeline with a control element indicates a controlling entity or manager. It organizes and
schedules the interactions between the boundaries and entities and serves as the mediator
between them.
Activation Bars
Activation bar is the box placed on the lifeline. It is used to indicate that an object is active (or
instantiated) during an interaction between two objects. The length of the rectangle indicates the
duration of the objects staying active.
In a sequence diagram, an interaction between two objects occurs when one object sends a
message to another. The use of the activation bar on the lifelines of the Message Caller (the
object that sends the message) and the Message Receiver (the object that receives the message)
indicates that both are active/is instantiated during the exchange of the message.
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.
An arrow from the Message Caller to the Message Receiver specifies a message in a sequence
diagram. A message can flow in any direction; from left to right, right to left or back to the
Message Caller itself. While you can describe the message being sent from one object to the
other on the arrow, with different arrowheads you can indicate the type of message being sent or
received.
The message arrow comes with a description, which is known as a message signature, on it. The
format for this message signature is below. All parts except the message_name are optional.
attribute = message_name (arguments): return_type
Operator
An operator specifies an operation on how the operands are going to be executed.
The operators in UML support operations on data in the form of branching as well as iteration.
Various operators can be used to ensure the use of iteration and branching in the UML model.
Following are the operators used in an interaction diagram:
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.
SEQUENCE DIAGRAM
A Sequence Diagram simply depicts interaction between objects in a sequential order. The
purpose of a sequence diagram in UML is to visualize the sequence of a message flow in the
system. The sequence diagram shows the interaction between two lifelines as a time-ordered
sequence of events.
A sequence diagram shows an implementation of a scenario in the system. Lifelines in
the system take part during the execution of a system.
In a sequence diagram, a lifeline is represented by a vertical bar.
In a sequence diagram, different types of messages and operators are used which are
described above.
In a sequence diagram, iteration and branching are also used.
Notations in Sequence Diagram
The above sequence diagram contains lifeline notations and notations of various messages used
in a sequence diagram such as create, reply, asynchronous message, etc.
Sequence diagram example
The following sequence diagram example represents McDonald’s ordering system:
If one changes the order of the operations, then it may result in crashing the program. It can also
lead to generating incorrect or buggy results. Each sequence in the above-given sequence
diagram is denoted using a different type of message. One cannot use the same type of message
to denote all the interactions in the diagram because it creates complications in the system.
You must be careful while selecting the notation of a message for any particular interaction. The
notation must match with the particular sequence inside the diagram.
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.
COLLABORATION DIAGRAM
Collaboration Diagram depicts the relationships and interactions among software objects. They
are used to understand the object architecture within a system rather than the flow of a message
as in a sequence diagram. They are also known as “Communication Diagrams.”
As per Object-Oriented Programming (OOPs), an object entity has various attributes associated
with it. Usually, there are multiple objects present inside an object-oriented system where each
object can be associated with any other object inside the system.
Collaboration Diagrams are used to explore the architecture of objects inside the system. The
message flow between the objects can be represented using a collaboration diagram.
The above collaboration diagram notation contains lifelines along with connectors, self-loops,
forward and reverses messages.
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 that occurs within an object of a system.
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 programs at various instances of time is represented
using a waveform.
In the above diagram, first, the software passes through the requirements phase then the design
and later the development phase. The output of the previous phase at that given instance of time
is given to the second phase as an input. Thus, the timing diagram can be used to describe SDLC
(Software Development Life Cycle) in UML.
Summary
The interactions are simply units of the behavior of a classifier.
The critical elements in an interaction diagram are lifeline and messages.
Interaction diagrams mostly focus on message passing.
Interaction diagrams capture the dynamic behavior of any system.
Interaction diagram contains sequence diagram, timing diagram,
communication/collaboration diagram.
The sequence UML diagram is to visualize the sequence of a message flow in the system.
The purpose of a collaboration diagram is to emphasize structural aspects.
Timing diagrams focus on the instance at which a message is sent from one object to another
object.