Section 8.1. Participants, Links, and Messages


8.1. 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 in Figure 8-1.

Figure 8-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 informationsometimes a participant is anonymous and does not have a namethen 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 in Figure 8-2.

Figure 8-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 diagramyou 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. Following this rule, in Figure 8-2, 1. messageA( ) is invoked first and then 2. messageB( ).

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 on Figure 8-3.

Figure 8-3. Nested messages on sequence diagrams are easy to see; when the initial message, message1(..), is invoked on participant2, participant2 then invokes the nestedmessage2(..) on participant3


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. An example of this nested message ordering is shown in Figure 8-4.

8.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 in Figure 8-5.

Figure 8-4. messageA( ) directly leads to nested 1.1 messageC( ), followed by nested messageD( ), before message 2 is invoked


Figure 8-5. Messages 2a. messageB( ), 2b. messageB( ), and 2c. messageC() are all invoked at the same time after 1. messageA( ) has been invoked


8.1.2. 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. Figure 8-6 shows how this looping constraint can be applied to a message on a communication diagram.

8.1.3. 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.

Figure 8-6. The addition of a new looping constraint to 1. messageA( ) means that the message will be invoked 10 times before the next set of messages2a, 2b, and 2ccan be invoked


A guard condition is made up of a logical Boolean statement. When the guard condition evaluates to true, the associated message will be invokedotherwise, the message is skipped.

Figure 8-7 shows how a guard condition can be applied to one of three concurrently executing messages.

Figure 8-7. a. 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


8.1.4. 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 in Figure 8-8.

Figure 8-8. The participant can invoke 1. messageA( ) on itself because it has a communication line to itself





Learning UML 2.0
Learning UML 2.0
ISBN: 0596009828
EAN: 2147483647
Year: 2007
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net