You are on page 1of 6

Focusing on Interaction Links:

Communication Diagrams 8

The main purpose of sequence diagrams is to show the order of events between the parts of your
system that are involved in a particular interaction. Communication diagrams add another
perspective to an interaction by focusing on the links between the participants.
Communication diagrams are especially good at showing which links are needed between
participants to pass an interaction’s messages. With a quick glance at a communication diagram,
you can tell which participants need to be connected for an interaction to take place. On a sequence
diagram, the links between participants are implied by the fact that a message is passed between
them. Communication diagrams provide an intuitive way to show the links between participants
that are required for the events that make up an interaction. On a communication diagram, the
order of the events involved in an interaction is almost a secondary piece of information.
N/B: Sequence and communication diagrams are so similar that most UML tools can automatically
convert from one diagram type to the other. The difference between the two approaches is largely
personal preference. If you’re happier looking at interactions from a link perspective, then
communication diagrams are likely to be for you; however, if you prefer to see the order of the
interactions as clearly as possible, then you’re likely to be in the sequence diagram camp.

Participants, Links, and Messages

A communication diagram is made up of three things: participants, the communication links


between those participants, and the messages that can be passed along those communication links,
as shown.

Figure 1: Much simpler than sequence diagrams, communication diagrams are made up of participants and links
Participants on a communication diagram are represented by a rectangle. The participant’s name
and class are then placed in the middle of the rectangle. A participant’s name is formatted as
<name> : <class>, similar to participants on a sequence diagram. You need to specify either the
participant’s name or class (or both). If, for some reason, you do not have both the name and class
information—sometimes a participant is anonymous and does not have a name—then either the
class or the name can be left out.

A communication link is shown with a single line that connects two participants. A link’s purpose
is to allow messages to be passed between the different participants; without a link, the two
participants cannot interact with each other. A communication link is shown:

Figure 2: Two messages are passed along the link between participant1 and participant2

A message on a communication diagram is shown using a filled arrow from the message sender to
the message receiver. Similar to messages on a sequence diagram, a message’s signature is made
up of the message name and a list of parameters. However, unlike sequence diagrams, the message
signature alone is not enough for a communication diagram—you also need to show the order in
which the messages are invoked during the interaction.
Communication diagrams do not necessarily flow down the page like sequence diagrams;
therefore, message order on a communication diagram is shown using a number before each
message. Each message number indicates the order in which that message is invoked, starting at 1
and increasing until all of the messages on the diagram are accounted for.
Things get more complicated when a message sent to a participant directly causes that participant
to invoke another message. When a message causes another message to be invoked, the second
message is said to be nested inside the original message, as shown:
Communication diagrams use their message numbering scheme to show the order of nested
messages. If we say that the initial message is numbered 1., then any messages nested within the
initial message begin with 1., adding a number after the decimal point for the ordering of the nested
messages. If an initial message’s number was 1., then the first nested message’s number would be
1.1.

Messages Occurring at the Same Time

Communication diagrams have a simple answer to the problem of messages being invoked at the
same time. Although sequence diagrams need complicated constructs, such as par fragments,
communication diagrams take advantage of their number-based message ordering by adding a
number-and-letter notation to indicate that a message happens at the same time as another
message, shown:

Invoking a Message Multiple Times

When describing the messages on a communication diagram, you likely will want to show that a
message is invoked a number of times. This is similar to showing that your messages will be
invoked in a for(..) loop if you are mapping your communication diagram’s participants to
software. Although UML does not actually dictate how a communication diagram can show that a
message is invoked a number of times, it does state that an asterisk should be used before a looping
constraint is applied. This rather complicated statement means that the following example is a safe
way to specify that something is going to happen 10 times:

*[i = 0 .. 9]

In the above looping constraint, i represents a counter that will count up from 0 to 9, doing
whatever task is associated with it 10 times.

Sending a Message Based on a Condition

Sometimes a message should be invoked only if a particular condition is evaluated to be true. For
example, your system might have a message that should be invoked only if the previous message
has executed correctly. Just as with sequence diagram fragments, communication diagram
messages can have guards set to describe the conditions that need to be evaluated before a message
is invoked.

A guard condition is made up of a logical Boolean statement. If the guard condition evaluates to
true, the associated message will be invoked—otherwise, the message is skipped.

Figure 3: messageB( ) will be invoked only at the same time as 2b. messageB( ) and messageC( ) if the expression condition ==
true is evaluated as true; if condition == true returns false, then 2a. messageB( ) is not invoked, but message 2b. messageB( )
and 2c. messageC( ) are

When a Participant Sends a Message to Itself

A participant talking to itself may sound strange at first, but if you think in terms of a software
object making a call to one of its own methods, you might start to see why this form of
communication is needed (and even common). Just as on sequence diagrams, a participant on a
communication diagram can send a message to itself. All that is needed is a link from the
participant to itself to enable the message to be invoked, as shown
Figure 4: The participant can invoke 1. messageA( ) on itself because it has a communication line

Feature Sequence diagrams Communication The result


diagrams
Shows participants Participants are Participants as well Communication
effectively mostly as links are the focus, diagrams
arranged along the so they are shown barely win. Although
top of clearly as rectangles. both types of diagram
page, unless the drop- can show participants
box as effectively as each
participant creation other, it can be
notation is used. It is argued
easy to gather the that communication
participants involved diagrams have the
in a particular edge since
interaction. participants are one
of their
main focuses.
Showing the links Links are implied. If Explicitly shows the Communication
between participants a message is passed links diagrams win
from one participant between participants. because they
to another, then it is In fact, this is the explicitly and clearly
implied that a link primary purpose of show the links
must these types of between participants.
exist between those diagram.
participants.
Showing message Message signatures Message signatures Draw! Both types of
signatures can be fully can be diagram can show
described. fully described. messages as
effectively as each
other.
Supports parallel With the introduction Shown using the Draw! Both types of
messages of sequence numberletter notation diagram show
fragments, sequence on message parallel messages
diagrams are much sequences. equally well
better.
Supports Achieved using the Communication Sequence diagrams
asynchronous asynchronous arrow diagrams are a
messages (fire and have no concept of clear winner here
forget) the because
asynchronous they explicitly
message support asynchronous
since its focus is not messages.
on
message ordering.
Easy to read message This is a sequence Shown using the Sequence diagrams
ordering diagram’s numberpoint-nested are a clear winner
forté. Sequence notation. here since they
diagrams really show off
clearly show message message ordering
ordering using the clearly and
vertical placement of effectively
messages down the
diagram’s page.
Easy to create and Creating a sequence Communication This is a difficult one
maintain the diagram diagram is fairly diagrams to judge and is
simple. However, are simple enough to largely based on
aintaining sequence create; personal preference.
diagrams can be a however, However,
nightmare unless a maintenance, communication
helpful UML tool is especially if message diagrams do have
being used. numbering needs to the edge on the ease-
be changed, still of-maintenance
ideally needs the stakes.
support of a helpful
UML tool.

You might also like