Professional Documents
Culture Documents
Focusing On Interaction Links: Communication Diagrams: Participants, Links, and Messages
Focusing On Interaction Links: Communication Diagrams: Participants, Links, and Messages
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.
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.
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:
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.
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
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