Archyno
UMLVerhaltensdiagramme

Sequenz- vs Kommunikationsdiagramm

Derselbe Bestellvorgang zweimal gezeichnet, damit der Kompromiss sichtbar statt beschrieben ist: das eine legt die Zeit auf die senkrechte Achse, das andere die Struktur auf die Seite und nummeriert die Nachrichten.

7 Min. LesezeitUML 2.5.127 von 35

1: placeOrder(cart)2: reserve(items)3: charge(total)4: save(order)Customer: OrderController: Inventory: PaymentGateway: OrderRepo
The checkout as a communication diagram: the structure is immediate, the order lives in the numbers.

01One interaction, two drawings

Both diagrams below describe the same checkout: a customer places an order, the controller reserves stock, charges a card, saves the order and replies. Nothing about the system differs between them. Only the axis the notation spends its space on does.

Customer: OrderController: Inventory: PaymentGateway: OrderRepoplaceOrder(cart)reserve(items)reservedcharge(total)authorisedsave(order)confirmation
The same checkout as a sequence diagram: order is the vertical axis, and the nesting of calls is visible in the activation bars.

Read the hero figure again after that one. The communication diagram makes something obvious that the sequence diagram buries: every message passes through OrderController. Four links radiate from one node and none connect to each other, which is the shape of the design rather than the shape of the run. On the sequence diagram that fact is spread over seven rows and you have to look for it.

And the reverse is just as true. On the sequence diagram you can see at a glance that the card is charged after stock is reserved, and that the reservation reply comes back before the charge goes out. On the communication diagram that ordering is the difference between the numerals 2 and 3.

02What each one spends its space on

The two notations are defined over the same underlying interaction in UML, so this is a presentation choice rather than a modelling one. What follows from that choice is consistent enough to tabulate.

ElementNotationWhat it means
OrderSequenceRead down the page, with no counting. On a communication diagram you follow the numbers, which is slower past about six messages.
StructureCommunicationThe links are the layout, so hubs, chains and isolated participants are visible immediately. A sequence diagram has no layout to read.
NestingSequenceActivation bars show which call is still on the stack. Communication diagrams express it as decimal numbering - 2.1 inside 2 - which is harder to scan.
Conditionals and loopsSequenceCombined fragments (alt, opt, loop) frame a region of the diagram. Communication diagrams have only guards on message labels.
Number of participantsCommunicationA sequence diagram runs out of horizontal room past six or seven lifelines. A communication diagram lays them out in two dimensions.
Being understoodSequenceFar more people can read one without being taught. That is not a property of the notation, but it decides most real choices.

The same information, two very different reading experiences.

03Choosing between them

The decision is easier if you write the sentence the diagram is meant to make somebody say. If the sentence has an order in it, you want lifelines. If it has a shape in it, you want links.

Reach for it when

  • Sequence, when the point is what happens before what - protocols, handshakes, race conditions.
  • Sequence, when conditionals and loops are part of the story and you need alt or loop frames.
  • Communication, when the point is who talks to whom - coupling, a hub, a layering violation.
  • Communication, when there are more participants than fit across a page as lifelines.

Reach for something else when

  • Communication, when the audience has to be taught the numbering before they can read it.
  • Sequence, when you are really describing structure - that is a class or component diagram.
  • Both, when neither order nor collaboration is in question. Prose is shorter.
  • Drawing the same interaction twice as documentation. Keep one; a tool can regenerate the other.

In practice most teams draw sequence diagrams and read the occasional communication diagram, which is a reasonable equilibrium: order is what people are usually trying to explain. The one place the communication diagram earns its keep outright is a design review about coupling, where four links converging on one node makes the argument faster than any list of call sites.

04What to remember

In one line each

  1. 01Both notations describe the same interaction. The choice is about what a reader notices first.
  2. 02Sequence puts order on the vertical axis; communication puts structure on the page and numbers the messages.
  3. 03Nesting is an activation bar on one and a decimal number on the other.
  4. 04Only sequence diagrams have alt, opt and loop frames - conditionals are why most teams stay with them.
  5. 05Communication diagram and collaboration diagram are the same picture under UML 2 and UML 1 names.

05Häufige Fragen

Was ist besser, ein Sequenz- oder ein Kommunikationsdiagramm?

Keines ist besser, sie betonen verschiedene Achsen. Das Sequenzdiagramm macht die Reihenfolge offensichtlich und die Struktur schwer erkennbar. Das Kommunikationsdiagramm macht die Form der Zusammenarbeit offensichtlich und die Reihenfolge mühsam. Wählen Sie die Stärke, die zu Ihrer Frage passt.

Enthalten Sequenz- und Kommunikationsdiagramm dieselbe Information?

Semantisch ja - beide beschreiben eine Interaktion, und UML definiert sie über demselben Modell, sodass ein Werkzeug das eine aus dem anderen erzeugen kann. Unterschiedlich ist nur, was ein Mensch zuerst bemerkt, und das ist der einzige Grund für zwei Notationen.

Warum nummerieren Kommunikationsdiagramme ihre Nachrichten?

Weil es keine Zeitachse gibt, an der man die Reihenfolge ablesen könnte. Die Nummerierung trägt sie stattdessen, und verschachtelte Nummern wie 2.1 und 2.2 zeigen, welche Aufrufe innerhalb welcher stattfinden. Ohne Nummern sagt das Diagramm nicht mehr, was wann geschieht.

Kann man ein Sequenzdiagramm in ein Kommunikationsdiagramm umwandeln?

Ja, und rein mechanisch. Jede Lebenslinie wird ein Knoten, jede Nachricht eine nummerierte Beschriftung an der Verbindung zweier Knoten, und die Reihenfolge von oben nach unten wird die Nummerierung. Viele Werkzeuge wandeln aus einer gespeicherten Interaktion in beide Richtungen um.

Warum werden Kommunikationsdiagramme so selten verwendet?

Die meisten wollen genau die Reihenfolge mitteilen, und sie aus einer Zahlenmenge abzulesen ist langsamer, als sie von oben nach unten zu lesen. Das Kommunikationsdiagramm gewinnt, wenn es darum geht, wer mit wem spricht, nicht in welcher Reihenfolge - und das ist der kleinere Teil echter Gespräche.

Alle Artikel