UML - Collaboration Diagrams



Collaboration diagrams, also known as communication diagrams, are part of UML. They emphasize how objects interact to complete specific tasks during a scenario or use case, giving a clear view of a system's dynamic behavior.

A collaboration diagram illustrates the relationships between objects within a system. While both sequence diagrams and collaboration diagrams convey the same information, they do so in distinct ways. Rather than depicting the flow of messages, the collaboration diagram focuses on the architecture of the objects present in the system, as it adheres to object-oriented programming principles.

Each object includes various features, and multiple objects in the system are interconnected. Also referred to as a communication diagram, the collaboration diagram is used to depict the structure of the objects within the system.

Notations of a Collaboration Diagram

The key components of a collaboration diagram are outlined below −

Objects

An object is depicted using an object symbol that shows its name and class, both underlined and separated by a colon. In collaboration diagrams, objects are used in the following ways −

  • The object is represented by specifying its name along with its class.
  • It's not required for every class to be shown.
  • A class may represent multiple objects.
  • The object is defined first, followed by its class.
  • Naming objects is essential to distinguish one from another.

Actors

Actors play a central role in collaboration diagrams, as they initiate interactions. Each actor has a specific role and name, with one actor initiating the use case.

Links

A link, representing an association, connects objects and actors. It shows the relationship between objects through which messages are exchanged. Represented by a solid line, the link allows an object to navigate or connect with another object, carrying message flows attached to it.

Messages

Messages represent communication between objects, conveying information with a sequence number to indicate the order of actions. They are shown as labeled arrows placed near links. Messages are sent from a sender to a receiver, and the direction must be clear and understandable to the receiver for proper communication.

When to Use a Collaboration Diagram?

Collaboration diagrams are used when it is important to illustrate the relationships between objects. Although both sequence diagrams and collaboration diagrams convey the same information, they present it in different ways. Collaboration diagrams are particularly useful for analyzing use cases.

Here are some specific use cases where a collaboration diagram is applied −

  • To model the interaction among objects or roles that execute the functionalities of use cases and operations.
  • To visualize the mechanisms within the system's architectural design.
  • To capture interactions representing the flow of messages between objects and roles in the collaboration.
  • To model various scenarios within a use case or operation that involve multiple objects and interactions.
  • To assist in identifying the objects involved in a use case.

In collaboration diagrams, each message is assigned a sequence number, where the top-level message is labeled as "1," and the numbering continues accordingly. Messages that occur within the same call are assigned the same decimal prefix but differ in their suffixes (e.g., 1.1, 1.2) based on the order of occurrence.

Creating a Collaboration Diagram

The following are the steps for creating a collaboration diagram −

  • Determine Behavior − Determine the behavior for which the realization and implementation are specified.
  • Discover Structural Elements − Discover the structural elements that are class roles, objects, and subsystems for performing the functionality of collaboration.
  • Choose Interaction Context − Choose the context of an interaction: system, subsystem, use case, and operation.
  • Consider Alternative Situations − Think through alternative situations that may be involved.
  • Implement Collaboration Diagram − Implementation of a collaboration diagram at an instance level, if needed.
  • Create Specification Level Diagram − A specification level diagram may be made in the instance level sequence diagram for summarizing alternative situations.

Advantages of a Collaboration Diagram

The following are the advantages of a collaboration diagram −

  • The collaboration diagram is also referred to as the Communication Diagram.
  • It primarily emphasizes the structural aspect of an interaction diagram, i.e., how lifelines are connected.
  • The syntax of a collaboration diagram is similar to the sequence diagram, with the only difference being that the lifeline does not have tails.
  • The messages transmitted over sequencing are represented by numbering each individual message.
  • The collaboration diagram is semantically weaker in comparison to the sequence diagram.
  • A special case of a collaboration diagram is the object diagram.
  • It focuses on the elements, not the message flow, as in sequence diagrams.
  • Since collaboration diagrams are not as costly, the sequence diagram can be directly converted into the collaboration diagram.
  • There may be a loss of some information when implementing a collaboration diagram compared to the sequence diagram.
Advertisements