What is Collaboration Diagram?
A collaboration Diagram depicts the relationships and interactions among software objects. It is used to understand the object architecture within a system rather than the flow of a message as in a sequence diagram. They are also known as “Communication Diagrams.” Collaboration Diagrams (known as Communication Diagrams in UML 2. x) are used to show how objects interact to perform the behavior of a particular use case or a part of a use case. Along with sequence diagrams, collaboration is used by designers to define and clarify the roles of the objects that perform a particular flow of events in a use case. They are the primary source of information used to determine class responsibilities and interfaces.
As per Object-Oriented Programming (OOPs), an object entity has various attributes associated with it. Usually, there are multiple objects present inside an object-oriented system and each object can be associated with any other object inside the system. Collaboration Diagrams are used to explore the architecture of objects inside the system. The message flow between the objects can be represented using a collaboration diagram.
The Need for Collaboration Diagram
Unlike a sequence diagram, a collaboration diagram shows the relationships among the objects. Sequence diagrams and collaboration diagrams express similar information but show it in different ways.
Because of the format of the collaboration diagram, they tend to be better suited for analysis activities (see Activity: Use-Case Analysis). Specifically, they tend to be better suited to depicting simpler interactions of smaller numbers of objects. However, if the number of objects and messages grows, the diagram becomes increasingly hard to read. In addition, it is difficult to show additional descriptive information such as timing, decision points, or other unstructured information that can be easily added to the notes in a sequence diagram. So, here are some use cases in that we want to create a collaboration diagram:
- Model collaborations between objects or roles that deliver the functionalities of use cases and operations
- Model mechanisms within the architectural design of the system
- Capture interactions that show the messages passing between objects and roles within the collaboration
- Model alternative scenarios within use cases or operations that involve the collaboration of different objects and interactions
- Support the identification of objects (hence classes) that participate in use cases
- Each message in a collaboration diagram has a sequence number.
- The top-level message is numbered 1. Messages sent during the same call have the same decimal prefix but suffixes of 1, 2, etc. according to when they occur.
Components of Collaboration Diagram
- Objects: The representation of an object is done by an object symbol with its name and class underlined, separated by a colon. In the collaboration diagram, objects are utilized in the following ways:
- The object is represented by specifying its name and class.
- It is not mandatory for every class to appear.
- A class may constitute more than one object.
- In the collaboration diagram, firstly, the object is created, and then its class is specified.
- To differentiate one object from another object, it is necessary to name them.
- Actors: In the collaboration diagram, the actor plays the main role as it invokes the interaction. Each actor has a respective role and name. In this, one actor initiates the use case.
- Links: The link is an instance of association, which associates the objects and actors. It portrays a relationship between the objects through which the messages are sent. It is represented by a solid line. The link helps an object connect with or navigate to another object, such that the message flows are attached to links.
- Messages: It is a communication between objects which carries information and includes a sequence number, so that the activity may take place. It is represented by a labeled arrow, which is placed near a link. The messages are sent from the sender to the receiver, and the direction must be navigable in that particular direction. The receiver must understand the message.
Benefits and Drawbacks of a Collaboration Diagram
Benefits of a Collaboration Diagram
- It reinforces the structural aspects of an interaction system which is how the lifeline is connected.
- Messages transmitted over sequencing are shown by the hierarchical numeration of each message.
- It enables to focus on the structural elements and not on the flow of message as stated in sequence diagrams.
Drawbacks of a Collaboration Diagram
- Exploring every object in the diagram is not easy.
- An object’s state changes frequently, which makes it troublesome to keep track of every change in every object present in the system.
- There are instances when there are too many objects present in the collaboration diagram and this can crowd the diagram.