Komponentendiagramm-Beispiele
Fünf Komponentendiagramme von Systemen, an denen Sie vermutlich schon gearbeitet haben. Jedes klärt eine Frage: Wer darf wen aufrufen, was müsste ein Ersatz erfüllen, und wo läuft eine Abhängigkeit in die falsche Richtung.
9 Min. LesezeitUML 2.5.18 von 23
01How to read the five
Every diagram below uses the same three marks, and if you can read them you can read all five: a component is a box with the plug icon, an «interface» is a box naming a contract, and the arrows say which side of that contract each component is on. A dashed arrow with a hollow triangle means I implement this. A plain dashed arrow means I need this. The full set is in component diagram symbols, and the reasoning behind the notation is in the component diagram guide.
They are ordered by how often the shape turns up rather than by complexity. Each one names the question it settles, because a component diagram that settles nothing is the most common kind and the least useful: five boxes, five arrows, and no statement anybody could disagree with.
032. Ports and adapters
Read the arrows and notice what the Ordering core does not touch. It does not depend on HTTP and it does not depend on PostgreSQL. It realizes one contract and requires another, and both of those are boxes it could have been handed by anybody.
This is the shape people mean by hexagonal architecture, ports and adapters, or clean architecture, and a component diagram is the cheapest way to check whether a codebase actually has it. If the core box has an arrow pointing at a database component rather than at an interface, the pattern is aspirational: something in the middle imports the driver.
043. One contract, two implementations
This is the diagram to draw before a replacement, not after. The claim it makes is precise and testable: everything the order service needs from billing is in IBilling, so a second implementation of that interface can be switched in without the order service changing.
It is also the fastest way to find out that the claim is false. If somebody says "the new service cannot do statement PDFs", then statement PDFs were part of the contract and are missing from the interface, and the diagram was wrong before the migration was. That conversation costs ten minutes at a whiteboard and three months in production.
Once the old implementation is gone, delete it from the diagram. A component diagram that still shows the mainframe two years after it was switched off is the reason people stop trusting the diagrams.
054. A plugin architecture
Topologically this is example three with a third implementation added, and that similarity is worth sitting with: replaceability and extensibility are the same drawing. What differs is intent. In a migration the extra realization is temporary; in a plugin architecture it is the product.
The reading technique that pays here is to cover the right-hand column with your hand. What remains - the host and IExporter- is everything a fourth exporter author needs to know. If the answer to "can I write my own exporter?" requires reading the host's source, the interface is under-specified and the diagram has just told you so.
065. The one with a cycle
Two services, each realizing a contract the other requires. Nothing here is illegal UML and nothing on the diagram is wrong - the drawing is an accurate picture of a system that is going to be difficult, which is precisely what you want a diagram to be able to say.
A cycle between components means neither can be understood alone: no independent deployment, no test in isolation without a stub of the other, and a replacement of either has to satisfy a contract the other one is simultaneously depending on. On a class diagram a cycle is a smell; between deployable units it is a schedule risk.
The usual fixes are visible on the same picture. Move what shipping needs from IOrders into an event the orders service publishes, so the arrow becomes one-way. Or extract the shared part into a third component both depend on, which turns the cycle into a fan-in and puts you back at example one.
In one line each
- 01Fan-in (example 1): one contract with several consumers - name it once, change it once.
- 02Chain (example 2): the core depends on interfaces at both ends, on implementations at neither.
- 03Two realizations (example 3): the migration claim, written down where it can be falsified.
- 04Many realizations (example 4): the same drawing as a migration, meant permanently.
- 05A cycle (example 5): an honest picture of a system that cannot be deployed or replaced piecemeal.
- 06If a diagram settles no argument, it is decoration - delete it rather than maintaining it.
To draw one of these against your own system, the step-by-step version is in how to draw a component diagram. For where these components run rather than what they promise each other, that is a deployment diagram.
07Häufige Fragen
Was ist ein gutes Beispiel für ein Komponentendiagramm?
Das nützlichste Beispiel ist das kleinste, das eine Streitfrage klärt: zwei oder drei Komponenten, die Schnittstellen dazwischen, sonst nichts. Ein Diagramm eines geteilten Katalogs, den Web und App nutzen, sagt mehr als eine Wand aus vierzig Kästen - der Leser erfasst es auf einmal und kann es gegen den Code prüfen.
Kann ein Komponentendiagramm Microservices zeigen?
Ja, und es ist eine der besseren Anwendungen. Jeder Service wird eine Komponente, jede veröffentlichte API eine Schnittstelle, und das Diagramm sagt genau, welcher Service welchen Vertrag aufrufen darf. Nicht zeigen darf es, wo die Services laufen - das ist ein Verteilungsdiagramm.
Wie viele Komponenten gehören auf ein Diagramm?
Drei bis etwa neun. Unter drei gibt es keine Struktur zu zeichnen, über neun oder zehn hört der Leser auf, Pfeilen zu folgen, und überfliegt nur noch - ab da ist das Diagramm Dekoration. Ein grosses System wird als mehrere Diagramme gezeichnet, eines je Frage.
Soll eine Datenbank als Komponente gezeichnet werden?
Zeichnen Sie den Adapter, nicht die Datenbank. Das Diagramm handelt vom Vertrag, von dem Ihr Code abhängt, also trägt eine Komponente PostgreSQL-Adapter, die IOrderStore realisiert, die nützliche Aussage. Das Datenbankprodukt selbst ist Infrastruktur und gehört ins Verteilungsdiagramm.
Passend dazu