Unit - 2: Collaboration Diagrams
Unit - 2: Collaboration Diagrams
Collaboration Diagrams:
A collaboration diagram is a behavioral UML diagram which is also referred to
as a communication diagram. It illustrates how objects or components interact
with each other to achieve specific tasks or scenarios within a system.
Importance of Collaboration Diagrams
Collaboration diagrams is important for understanding communication, design,
analysis, and documentation of the system's architecture and behavior.
• Visualizing Interactions:
o These diagrams offer a clear visual representation of how objects
or components interact within a system.
o This visualization helps stakeholders in understanding the flow of
data and control for easier understanding.
• Understanding System Behavior:
o By showing interactions, collaboration diagrams provide insights
into the system's dynamic behavior during operation.
o Understanding this behavior is important for identifying potential
issues, optimizing performance, and ensuring the system functions
smoothly.
• Facilitating Communication:
o Collaboration diagrams provide an effective communication tools
among team members.
o They facilitate discussions, enabling refinement of the system's
design, architecture, and functionality.
1. Objects/Participants
Objects are represented by rectangles with the object's name at the top.
Each object participating in the interaction is shown as a separate
rectangle in the diagram. Objects are connected by lines to indicate
messages being passed between them.
2. Multiple Objects
Multiple objects are represented by rectangles,each with the object's name
inside, and interactions between them are shown using arrows to indicate
message flows.
3. Actors
They are usually shown at the top or side of the diagram. Actors indicate their
involvement in the interactions with the system's objects or components. They
are connected to objects through messages, showing the communication with
the system.
4. Messages
Messages represent communication between objects. Messages are shown as
arrows between objects, indicating the flow of communication. Each message
may include a label indicating the type of message (e.g., method call, signal).
Messages can be asynchronous (indicated by a dashed arrow)
or synchronous (solid arrow).
5. Self Message
This is a message that an object sends to itself. It represents an action or
behavior that the object performs internally without involving any other objects.
Self-messages are useful for modeling scenarios where an object triggers its
own methods or processes.
6. Links
Links represent associations or relationships between objects. Links are shown
as lines connecting objects, with optional labels to indicate the nature of the
relationship. Links can be uni-directional or bi-directional, depending on the
nature of the association.
7. Return Messages
Return messages represent the return value of a message. They are shown as
dashed arrows with a label indicating the return value. Return messages are
used to indicate that a message has been processed and a response is being sent
back to the calling object.
Sequence Diagram:
A Sequence Diagram in UML (Unified Modeling Language) is used to model
the interactions between objects in a particular sequence. It shows how objects
communicate with each other in a specific order to carry out a process or
functionality.
Key Elements of a Sequence Diagram:
1. Actors: These are external entities interacting with the system (e.g., users
or other systems).
2. Objects/Instances: Represent the entities (typically classes or
components) involved in the interaction.
3. Lifelines: Vertical dashed lines representing the lifespan of an object
during the interaction.
4. Messages: Arrows showing communication between objects. They
represent method calls or events triggered by other objects.
o Synchronous messages: Represented by a solid arrowhead and
imply that the sender waits for a response.
o Asynchronous messages: Represented by an open arrowhead and
imply the sender does not wait for a response.
5. Activation Bars: Rectangles placed on the lifeline to represent when an
object is active or performing a process.
6. Return Messages: Dotted arrows that show the return of data or control
from a method call.
7. Destruction: A cross at the end of a lifeline indicates that an object is
destroyed (optional).
The above sequence diagram depicts the sequence diagram for an emotion
based music player:
• Firstly the application is opened by the user.
• The device then gets access to the web cam.
• The webcam captures the image of the user.
• The device uses algorithms to detect the face and predict the mood.
• It then requests database for dictionary of possible moods.
• The mood is retrieved from the database.
• The mood is displayed to the user.
• The music is requested from the database.
• The playlist is generated and finally shown to the user.
BEHAVIORAL MODELING-
In UML (Unified Modeling Language), behavioral modeling focuses on how a
system behaves in response to events, user actions, or interactions between
objects. These models help in understanding the dynamic aspects of the system
and represent how various parts of the system cooperate and respond over time.
2. Activity Diagram
An Activity Diagram is used to model the workflow or flow of control
between actions in a system. It shows how an activity (task) progresses from
one step to the next, typically based on some conditions or inputs.
Key Elements:
• Action: Represents a task or operation.
• Activity: A collection of actions.
• Decision Node: A point where control diverges based on conditions (like
an if-else).
• Fork/Join: Used to represent parallel processing (fork splits, join
synchronizes).
• Start and End Nodes: Represent the initiation and termination of the
workflow.
• Control Flow: Arrows indicating the direction of activity or decision.
Example: Online Payment Process
• Start: User decides to make a payment.
• Decision: Is the payment valid?
o If valid, process payment.
o If invalid, ask the user to correct the information.
• End: Successful or failed payment.
Activity Diagram for Payment Processing:
+-------------------------+
| Start |
+-------------------------+
|
v
+-------------------------+
| User Enters Payment Info |
+-------------------------+
|
v
+-------------------------+
| Validate Payment Info |
+-------------------------+
| |
Valid Invalid
| |
v v
+---------------------+ +-----------------------+
| Process Payment | | Ask for Correct Info |
+---------------------+ +-----------------------+
| |
v v
+---------------------+ +-----------------------+
| Payment Successful | | User Corrects Info |
+---------------------+ +-----------------------+
|
v
+-------------+
| End |
+-------------+
• States: The order starts in the Order Pending state, then transitions
through various states (e.g., Order Shipped) based on events.
• Event Triggered Transitions: A "Shipped" event transitions the order to
Shipped, and a "Delivered" event transitions it to the Delivered state.
6. Time Diagram
A Timing Diagram represents the behavior of an object over time, particularly
useful for real-time systems or time-sensitive interactions. It shows how objects
change their states or how signals are exchanged over time.
Key Elements:
• Lifeline: Represents the object whose state is being modeled.
• State/Value: Changes that occur on the object over time.
• Time Axis: Horizontal axis representing time.
Example**: Timer Triggered Event
+------------------+ +-------------------+ +------------------+
| Object A | | Object B | | Object C |
+------------------+ +-------------------+ +------------------+
| | | | |
---|---|--------------|--------|--------------------|------------------|---
[Event Triggered]
7. Interaction Diagrams
Interaction Diagrams model how objects interact with each other over time.
There are two main types:
• Sequence Diagrams: Focus on the time sequence of messages exchanged
between objects.
• Communication Diagrams: Focus on the relationships between objects
and the messages exchanged.
Sequence Diagram:
Sequence diagrams emphasize the time order of messages between objects. It
represents the interactions by focusing on the sequence of events.
Example: Customer Order Flow
+------------+ +-------------+ +-----------+
| Customer | | OrderSystem | | Database |
+------------+ +-------------+ +-----------+
| | |
|----(1) Order------>| |
| |----(2) Query DB------>|
| | |
| |<---(3) Return Data---|
|<---(4) Confirmation-|
8. Package Diagram
A Package Diagram is used to organize the system into packages or modules.
It helps show dependencies between different parts of the system and their
relationships.
Key Elements:
• Package: A group of related classes or components.
• Dependency: Represents a relationship between two packages.
Example: Library System
+----------------+ +---------------------+
| User Interface | | Business Logic |
| Package | | Package |
+----------------+ +---------------------+
| |
<<depends on>> <<depends on>>
| |
+------------------+ +---------------------+
| Database Package | | Payment Processing |
+------------------+ +---------------------+
User Interface depends on the Business Logic package for core functionality,
while Business Logic depends on the Database and Payment packages.
Architectural Modeling:
Architectural modeling in UML (Unified Modeling Language) focuses on the
structure and organization of a system's components, as well as how these
components are deployed onto hardware. This type of modeling is essential for
understanding how a system is built, how its parts interact, and how the system
is distributed across physical infrastructure.
Key UML diagrams used in architectural modeling are:
1. Component Diagram
2. Deployment Diagram
C. Component Diagram
A Component Diagram is used to model the logical architecture of a system,
showing how different components interact and depend on each other. It focuses
on the software structure, particularly the decomposition of the system into
reusable and interchangeable components.
Key Elements in a Component Diagram:
1. Component: Represents a modular unit of software that encapsulates
specific functionality.
o Example: A "Database Component" that interacts with the
database.
2. Interface: Defines a set of services or operations that a component
provides or requires.
o Example: A "Payment Gateway Interface" that defines how
payment transactions are processed.
3. Port: A specific point through which a component interacts with other
components, typically representing an interaction point for services.
o Example: A "Web Service Port" that allows other components to
interact with a web service.
4. Dependency: Represents how one component relies on another. It is
shown with a dashed arrow indicating that a component depends on the
functionality of another.
o Example: A "Shopping Cart" component that depends on a
"Payment" component to complete purchases.
5. Realization: A relationship where a component provides the behavior
defined by an interface. This is typically denoted with a solid line with a
hollow triangle at the end.
6. Ports and Connectors: Used to model the interaction between components
and interfaces.
Purpose of Component Diagrams:
• Visualizing modularity: Component diagrams help to break down the
system into smaller, manageable units of functionality, showing the
system’s modular structure.
• Defining components and interfaces: It helps define the components, their
interfaces, and the dependencies between them.
• Understanding interactions: Component diagrams help understand how
various components interact with each other to provide the system’s
overall functionality.
Example of a Component Diagram:
For an Online Banking System:
+-----------------------+
| User Interface |
| (UI Component) |
+-----------------------+
|
v
+-----------------------+ +------------------------+
| Authentication Service |<------>| Database Component |
| (Component) | | (Artifact) |
+-----------------------+ +------------------------+
|
v
+-----------------------+
| Payment Processing |
| (Component) |
+-----------------------+
D.Deployment Diagram
A Deployment Diagram is used to model the physical deployment of software
components onto hardware nodes. It shows how software is distributed across
hardware devices and how the components communicate with each other in a
runtime environment.
Key Elements in a Deployment Diagram:
1. Node: A physical or virtual machine that executes software components.
Nodes can represent physical devices (like servers or workstations) or
virtual resources (like cloud instances or containers).
o Example: A "Web Server" node or a "Database Server" node.
2. Component: A software artifact (e.g., an executable file, a web
application) deployed on a node.
o Example: A "Web Application" component that is deployed on a
"Web Server".
3. Artifact: A tangible software package or file that is deployed on a node.
o Example: A .war file (web application archive) deployed on a web
server node.
4. Communication Path: Represents the network or communication
channels between nodes. It shows how nodes exchange data or messages.
o Example: A communication link between a "Web Server" node and
a "Database Server" node for querying data.
5. Deployment Specification: Constraints or configurations that influence
how software components are deployed onto nodes (e.g., operating
system requirements, load balancing, resource limitations).
Purpose of Deployment Diagrams:
• Visualizing the physical structure: Deployment diagrams illustrate how
software components are physically distributed across hardware, making
it easier to understand system architecture at the deployment level.
• Mapping logical components to physical infrastructure: It helps relate
software components to physical resources, providing insights into the
hardware requirements and resource utilization.
• Understanding performance and scalability: Helps in planning how the
system will scale across multiple machines and how components will
communicate over a network.
Example of a Deployment Diagram:
For an E-commerce Application:
+-------------------+ +---------------------+ +--------------------+
| Web Server | | Application Server | | Database Server |
| (Node) | | (Node) | | (Node) |
|-------------------| |---------------------| |--------------------|
| [Web App] | | [Order Processing] | | [MySQL Database] |
+-------------------+ +---------------------+ +--------------------+
| | |
+-------------------------+-----------------------------+
|
+-----------------------+
| Payment Gateway |
| (Artifact) |
+-----------------------+
Nodes:
• Web Server node: Hosts the Web App.
• Application Server node: Hosts the Order Processing component.
• Database Server node: Hosts the MySQL Database.
• Payment Gateway is deployed on a different physical or virtual node.
Communication Paths:
• Web Server communicates with the Application Server to handle user
requests and process orders.
• Application Server communicates with the Database Server to retrieve
order data and update inventory.