Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 39 ยท Sequence and Communication Diagrams

Communication Diagrams

Learn UML communication diagrams: objects connected by links with numbered messages, decimal numbering for nesting, how they differ from sequence diagrams, and when to choose them.

A communication diagram (called a collaboration diagram in UML 1) shows the same kind of information as a sequence diagram, but arranged differently. Instead of lifelines and time flowing downward, it draws the objects and the links between them, and numbers each message to give the order. It answers "which objects work together, and how are they connected?" more directly than a sequence diagram does.

Notation

  • Objects (or roles) as rectangles labelled name : Class.
  • Links as solid lines between objects that can exchange messages. A link must correspond to an association or other possibility in the class diagram.
  • Messages as arrows next to a link, each with a sequence number and an operation name: 1: placeOrder(cart).
  • Numbers show order. Replies are normally omitted unless the value matters.

Mermaid has no communication diagram type, so we use a flowchart: boxes for objects, numbered labels on arrows.

flowchart LR
    U["user : Customer"] -- "1: placeOrder(cart)" --> S["svc : OrderService"]
    S -- "2: checkStock(items)" --> I["inv : Inventory"]
    S -- "3: charge(total)" --> P["pay : PaymentGateway"]
    S -- "4: save(order)" --> D["db : OrderRepository"]

One customer interaction. The objects and their links are visible at once; the numbers give the order.

Numbering rules

Numbers are what make a communication diagram work.

Style Example Meaning
Simple 1, 2, 3 Messages in order
Decimal (nested) 1, 1.1, 1.2, 2 Message 1.1 and 1.2 are sent during the processing of message 1
Letter 1a, 1b Concurrent messages
Guard 2 [stock ok]: reserve() Conditional message
Iteration 3 *[for each line]: add() Repeated message

The decimal style records nested calls. Take the order scenario: 1: placeOrder triggers 1.1: checkStock and 1.2: charge; only then does control return and 2 run.

flowchart LR
    C["c : Cart"] -- "1: checkout()" --> O["o : OrderService"]
    O -- "1.1: validate(cart)" --> V["v : Validator"]
    O -- "1.2: reserve(items)" --> I["i : Inventory"]
    O -- "1.3: charge(total)" --> P["p : PaymentGateway"]
    O -- "2: save(order)" --> R["r : OrderRepository"]

Messages 1.1 to 1.3 run inside message 1. Message 2 comes after.

Communication vs sequence diagrams

Both are interaction diagrams and describe the same scenarios. The difference is what they emphasize.

Sequence diagram Communication diagram
Emphasis Time order Structure and links
Layout Lifelines left to right, time downward Free; objects placed as you like
Order shown by Vertical position Message numbers
Strong at Complex flows, fragments (alt, loop) Seeing which objects are connected
Weak at Showing links between objects Long scenarios and control logic
Adding messages Easy to follow Numbers need renumbering

They are semantically equivalent for simple scenarios: you can convert one to the other without losing information. Many tools do it automatically.

Choose the sequence diagram when the order and logic is the point; choose the communication diagram when the object structure is the point, or when you are sketching on a whiteboard and want to move boxes around freely.

Pick an interaction diagram

Sequence Time order, fragments.
Communication Links and collaboration.
Timing Exact durations.
Overview Chain of interactions.

Same scenarios, different emphasis.

1 / 2

Converting between them

A communication diagram becomes a sequence diagram by listing messages in numbered order as arrows between lifelines. Here is the nested checkout diagram above, converted.

sequenceDiagram
    participant C as c : Cart
    participant O as o : OrderService
    participant V as v : Validator
    participant I as i : Inventory
    participant P as p : PaymentGateway
    participant R as r : OrderRepository
    C->>O: 1: checkout()
    O->>V: 1.1: validate(cart)
    O->>I: 1.2: reserve(items)
    O->>P: 1.3: charge(total)
    O->>R: 2: save(order)

The numbers are redundant in a sequence diagram, but keeping them helps readers match both views.

Python Sort numbered messages into their execution order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The sort key splits the decimal number into integers, so 1.10 correctly follows 1.9 (a string sort would not). The indentation reveals the nesting that the decimals encode.

Every pair of objects that exchange a message needs a link, and every link must be backed by an association or a dependency in the class diagram. This check is a handy consistency test.

Python Find the links a communication diagram needs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The checker flags OrderService -> PaymentGateway: either the class diagram forgot the association or the interaction should go through a different object. Both are useful findings.

Practical tips

  • Use communication diagrams for small scenarios with a handful of objects, typically up to eight.
  • Place the initiating object at the left or top, and the objects it calls to the right or below, so arrows flow naturally.
  • Number from 1, and use decimals for nested calls and letters for parallel ones.
  • Do not draw every reply; add a return value only if it matters.
  • Draw the links before the messages, then add messages next to them.
  • Combine with a class diagram nearby: the links should match the associations.

Use communication diagrams in workshops. Sticky notes for objects and arrows drawn with a marker make a fast way to design collaborations; once the team agrees, a sequence diagram can capture the final order.

Common mistakes

  • Missing numbers. Without them it is a plain object graph, with no order.
  • Messages without a link. An arrow between objects that are not linked is a design error.
  • Mixing structure and flow noise. Too many replies and trivial calls hide the collaboration.
  • Wrong nesting. 1.1 is a call made while handling 1, not a call that follows it.
  • Using it for complex logic. Branches and loops are clumsy here; use a sequence or activity diagram.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How does a communication diagram show message order?

    Numbers, usually with decimal nesting, carry the order.
  2. 2. What does message number 1.2 mean?

    Decimal numbers express nesting: 1.2 happens inside the processing of 1.
  3. 3. Which diagram is better at showing which objects are connected?

    Communication diagrams draw the links between objects explicitly.
  4. 4. What must every link in a communication diagram be backed by?

    Objects can only talk if the structure allows it.
  5. 5. When would you prefer a sequence diagram?

    Sequence diagrams handle ordering and combined fragments better.

Summary

  • Communication diagrams show objects, the links between them and numbered messages.
  • Decimal numbering (1, 1.1, 1.2) records nested calls; letters mark concurrency.
  • They are equivalent to sequence diagrams for simple scenarios but emphasize structure, not time.
  • Every link must exist in the class diagram; use this to check your design.
  • Keep them small and combine them with a class diagram.

Next: State Machine Diagrams