Introduction
Every software system is a conversation. Objects exchange messages, methods get triggered, and results are returned — all to make a feature work smoothly. UML’s Communication Diagram helps you visualize this dialogue.
While Sequence Diagrams show when messages are exchanged, Communication Diagrams focus on who talks to whom and in what order. Think of it as seeing the whole cast of characters and their conversations in one frame — a powerful companion when designing or debugging systems.
What is a Communication Diagram?
A Communication Diagram (formerly called a Collaboration Diagram) is a UML behavioral diagram that models the interactions between objects or parts based on message flow. The focus is on the relationships and structure, with a secondary emphasis on message sequencing.
Why Use a Communication Diagram?
- Understand object collaboration: Who interacts with whom?
- Visualize architectural layout: Highlights system structure alongside behavior
- Explore message paths: Discover how control flows through objects
- Complement sequence diagrams: Different perspective for the same scenario
Core Elements of a Communication Diagram
1. Objects (Participants)
Entities or components involved in the interaction. Represented as rectangles.
2. Links (Relationships)
Lines connecting objects, indicating an association through which messages are passed.
3. Messages
Calls from one object to another, labeled with sequence numbers (e.g., 1, 1.1, 1.2).
4. Sequencing
Numbers show the order of execution rather than actual timing. This helps visualize nested calls clearly.
Example Scenario: Student Login
Use Case
A student logs in. The login controller calls the authentication service, which in turn checks credentials via a user repository.
Objects Involved
student:Student(actor)loginCtrl:LoginControllerauth:AuthServicerepo:UserRepository
Message Flow
1: student -> loginCtrl: login("mark", "1234")
2: loginCtrl -> auth: validate("mark", "1234")
3: auth -> repo: findUser("mark")
4: repo --> auth: User
5: auth --> loginCtrl: true
6: loginCtrl --> student: showDashboard()
Java Implementation Mapping
This flow maps directly to method calls in Java:
public boolean login(String username, String password) {
User user = repo.findUser(username);
if (user != null && user.getPassword().equals(password)) {
return true;
}
return false;
}
How to Create a Communication Diagram (Step-by-Step)
Step 1: Choose the Use Case
Pick a scenario such as “Submit Assignment” or “Generate Report Card.”
Step 2: Identify Participants
List all involved objects or classes — services, repositories, controllers, etc.
Step 3: Draw Objects
Place each participant on the canvas as a rectangle. Include object names and classes (e.g., marksCtrl:MarksController).
Step 4: Connect with Links
Draw lines to represent associations or possible communication paths.
Step 5: Add Message Labels
Use numbered arrows to indicate message flow and call order. Nest deeper calls as 1.1, 1.2, etc.
Step 6: Review Message Order
Ensure messages are labeled sequentially and reflect the intended behavior of the use case.
Another Example: Uploading Marks
Participants
teacher:TeachermarksCtrl:MarksControllermarksService:MarksServicedb:MarksRepository
Messages
1: teacher -> marksCtrl: uploadMarks()
2: marksCtrl -> marksService: saveMarks()
3: marksService -> db: persist()
4: db --> marksService: success
5: marksService --> marksCtrl: success
6: marksCtrl --> teacher: confirmation
Communication vs Sequence Diagram
| Aspect | Sequence Diagram | Communication Diagram |
|---|---|---|
| Focus | Message sequence over time | Message routing among objects |
| Layout | Vertical lifelines | Network layout of objects |
| Readability | Clear message flow | Clear structural relationships |
| Best for | Understanding order | Understanding structure |
Best Practices
- Use precise object names: e.g.,
marksCtrl:MarksController - Stick to a single scenario: Avoid mixing use cases
- Label messages clearly: Numbered messages are crucial
- Keep the layout readable: Avoid overlapping arrows
When to Use Communication Diagrams
- Modeling control flow in a microservice or modular system
- Validating class-level responsibilities during design
- Clarifying how components coordinate in a use case
- Supporting object interaction design alongside sequence diagrams
Tools to Create Communication Diagrams
- StarUML: Native support for UML communication diagrams
- Lucidchart: Web-based visual modeling tool
- PlantUML: Text-to-diagram support with sequence-like notation
- draw.io: Easy drag-and-drop shapes and connectors
PlantUML Approximation
@startuml
object Teacher
object MarksController
object MarksService
object MarksRepository
Teacher -[#0000FF]> MarksController : 1. uploadMarks()
MarksController -[#0000FF]> MarksService : 2. saveMarks()
MarksService -[#0000FF]> MarksRepository : 3. persist()
MarksRepository -[#green]> MarksService : 4. success
MarksService -[#green]> MarksController : 5. success
MarksController -[#green]> Teacher : 6. confirmation
@enduml
Conclusion
UML Communication Diagrams offer a powerful lens to inspect object collaboration in your system. While sequence diagrams tell a time-based story, communication diagrams highlight structure and message flow at a glance. Together, they provide a well-rounded understanding of system behavior.
For developers working with Java, these diagrams help you architect clean, decoupled classes and services. Whether it’s a login process or grade submission flow, understanding communication patterns builds confidence in your design and coding decisions.
Next, we’ll look at State Machine Diagrams, where objects aren't just exchanging messages — they’re changing state.
