UML Collaboration Diagrams

A major task of the design phase is creating the interaction diagrams for the system operations. Read this section to learn more about collaboration diagrams. As you review the examples, consider general principles in assigning responsibilities. Ask yourself, how do you determine the relationship between objects? How can you extract the classes? How do you determine whether a mentioned feature can be considered a class attribute? How would you determine class methods?

UML Notation for Collaboration Diagrams

Collaboration diagrams have basic notations, as presented in Figure 4.1. Basic notations include: 

  • Instances: Represented the same as an object or class, but the name is underlined and always followed by a colon.
  • Links: This is a connection path between two objects to show some form of navigation and visibility instances. 
  • Message: messages are represented using an arrow on the link line. Messages are numbered to show the sequential order in which the messages are sent.
  • Parameter: Parameters are shown within parentheses following the message.

A collaboration diagram has more notations that can be used when need comes as follows:


Representing a return value 

Some messages sent to an object may require a return message. A return value may be shown by preceding the message with a return value variable name and an assignment operator (':=') as shown in Figure 4.3. The standard syntax for messages is:


Figure 4.3: Return Values in Collaboration Diagram


Representing iteration 

An object may repeatedly send a message to another object a number of times. This is indicated by prefixing the message with a start ('*') as in Figure 4.4.


Figure 4.4: Representing Iteration in Collaboration Diagram Representing the creation of instances

The UML creation message is create, which is independent of programming languages, shown being sent to the instance being created. Optionally, the newly created instance may include a < > symbol as shown in Figure 4.5. A create message can optionally take parameters when some attributes of the object to be created need to be set an initial value



Figure 4.5: Creation of an Instance in Collaboration Diagram


Representing message number sequencing 

The order of messages is illustrated with sequence numbers, as shown in Figure. The numbering scheme is: 

i. The first message is not numbered. Thus, msg1() is unnumbered.

ii. The order and nesting of subsequent messages is shown with a legal numbering scheme in which nested messages have appended to them a number. Nesting is denoted by pre-pending the incoming message number to the outgoing message number.



Figure 4.6: Message Number Sequencing in Collaboration Diagram


Representing conditional messages 

Sometimes, a message may be guarded and can be sent from one object to another only when a condition holds. At a point during the execution of an object, a choice of several messages, guarded by different conditions, will be sent. In a sequential system, an object can send one message at a time and thus these conditions must be mutually exclusive. When we have mutually exclusive conditional messages, it is necessary to modify the sequence expressions with a conditional path letter.



Figure 4.7: Conditional Message in Collaboration Diagram

Note that: 

  • Either 1a or 1b could execute after msg1() , depending on the conditions. 
  • The sequence number for both is 1, and a and b represent the two paths. 
  • This can be generalized to any number of mutually exclusive Conditional Messages.


Representing multiobjects 

We call a logical set of instances/objects as a multiobject. A multiobject is an instance of a container class; each instance of which is a set of instances of a given class (or type). E.g. SetOfSales is a class each instance of which is a set of sales. Each multiobject is usually implemented as a group of instances stored in a container or a collection object. In a collaboration diagram, a multiobject represents a set of objects at the "many" end of an association. In UML, a multiobject is represented as a stack icon as illustrated in Figure 4.8.


Figure 4.8: Multiobject and Message to Multiobject