Archyno
UMLPraxe modelování

Jak nakreslit diagram komponent

Šest kroků od prázdného plátna k diagramu, který se dá předat týmu, na jednom malém systému. Pořadí je důležitější než notace: části, pak sliby, pak potřeby a nakonec kontroly, které odhalí špatnou hranici dřív, než na ní někdo začne stavět.

8 min čteníUML 2.5.19 z 23

«use»«use»«use»DashboardScheduler«interface»IReportsReport service«interface»IWarehouseWarehouse adapter
Where the six steps end up: two consumers, one shared contract, and a service that reaches its warehouse through a second one. Twenty minutes of work, and every arrow is a claim somebody can check.

01Step 1. List what could be replaced

Before drawing anything, write a list. Not of your modules, not of your folders - of the parts of the system that could plausibly be swapped for a different implementation: bought instead of built, rewritten by another team, or run by somebody else.

That question is the whole filter. A folder is not a component and neither is a class; a thing with a boundary somebody could hand to a supplier is. The reporting system in this article produced four: a dashboard, a scheduler that runs reports overnight, the report service itself, and an adapter that talks to the data warehouse.

02Step 2. Draw the boxes, and no arrows

DashboardSchedulerReport serviceWarehouse adapter
Step two. Four components and deliberately nothing else - the arrows come after the contracts, not before them.

Place the parts and resist connecting them. Drawing arrows now means drawing them between components, and a line from Dashboard straight to Report service says only "these two are involved somehow", which is the vagueness a component diagram exists to remove.

Layout is worth thirty seconds here: put consumers on one side and providers on the other. Every diagram in this series is drawn left to right, dependencies flowing one way, because a reader can then check the direction at a glance rather than by following each line.

03Step 3. Name what each part provides

DashboardScheduler«interface»IReportsReport service«interface»IWarehouseWarehouse adapter
Step three. Two contracts, each drawn once and attached to the component that implements it by a dashed arrow with a hollow triangle.

For each box, ask what somebody outside it is allowed to rely on, and name that. IReports and IWarehouse here - one contract per capability, not one per consumer. Attach it with a realization: dashed line, hollow triangle, pointing at the interface.

This step is where the real design happens, and it is the step people skip. Naming a contract forces you to decide what is public, and the argument that follows - "is the CSV export part of IReports or not?" - is the argument worth having before two teams answer it differently in code.

04Step 4. Add what each part requires

Now the second half, and the half that carries the information: for each component, which contracts does it need? Draw a dependency - dashed line, open arrowhead - from the component to the interface it requires. The finished result is the diagram at the top of this article.

Two things become visible the moment those arrows land. The dashboard and the scheduler both point at IReports, so changing it is now visibly a change to two consumers. And the report service points at IWarehouse rather than at the adapter, so the adapter is replaceable without the service noticing - which is either what you intended or a discovery worth making now.

05Step 5. Run four checks

A component diagram is finished when it survives these. They take a minute and each one has caught a real problem more often than it has passed cleanly.

  1. Cover a box with your hand. What is left - the interfaces that were attached to it - is the specification of its replacement. If a replacement would need to know something that is not on screen, the boundary is in the wrong place.
  2. Follow the arrows for a cycle. Two components that require each other cannot be deployed, tested or replaced independently. See the last of the worked examples for what that looks like and how it gets broken.
  3. Check every component has at least one interface. A box with nothing attached is either not a component or not relevant to this diagram.
  4. Read the interface names aloud. If one is named after its current provider rather than its capability - IMainframeBilling rather than IBilling - the contract has the supplier baked into it, and the swap the diagram promises will not be as clean as it looks.

06Step 6. Delete what belongs on another diagram

Reach for it when

  • Interfaces, and which component is on which side of each
  • Stereotypes that change how a part is procured - «subsystem», «service», «library»
  • Ports, when one component genuinely has two separate surfaces
  • A note on any boundary that is contested, saying who decided it

Reach for something else when

  • Servers, regions, containers and processes - deployment diagram
  • Classes, fields and methods inside a component - class diagram
  • The call sequence between components - sequence diagram
  • Database tables and columns - ER diagram

The right-hand column is not pedantry about diagram kinds. Every item on it makes the picture bigger without answering the question this diagram was drawn for, and each one gives the diagram a second reason to go out of date: a component diagram survives a re-platforming untouched, and the same drawing with two AWS regions on it does not.

In one line each

  1. 01List what could be replaced. That list, not the folder tree, is your component list.
  2. 02Boxes first, no arrows - a line between two components states nothing checkable.
  3. 03Name the provided contracts before the required ones; that is where the design decisions are.
  4. 04Required interfaces carry the dependency information and are the half people omit.
  5. 05Cover any box: what remains must fully specify its replacement.
  6. 06Anything about machines, classes or call order belongs on a different diagram.

With the drawing done, the reference for every mark on it is in component diagram symbols, and the wider case for when this diagram kind is worth the effort at all is in the component diagram guide.

07Časté dotazy

Jak začít diagram komponent od nuly?

Začněte seznamem částí systému, které by šlo reálně vyměnit nebo koupit místo postavit, a zastavte se u devíti. Právě tato otázka, ne struktura složek, rozhoduje o tom, které boxy na diagram patří, a odpovědět na ni jako první je to, co zabrání, aby z kresby vznikl obrázek repozitáře.

Co je první, komponenty nebo rozhraní?

Nejdřív komponenty, ale jen jako boxy bez šipek. Pojmenovat smlouvy je ta těžká část a dělat ji druhou znamená pojmenovat je s vědomím, které části stojí na obou stranách, místo vymýšlení rozhraní a následného hledání něčeho, co za něj postavíte.

Jak podrobný má diagram komponent být?

Tak podrobný, aby někdo dokázal z okolí postavit náhradu kteréhokoli boxu, a nic víc. Operace a parametry patří do definice rozhraní nebo do kódu, ne na diagram - diagram, který vypisuje signatury metod, je zastaralý týden po nakreslení.

Podle čeho poznám, že je diagram komponent hotový?

Když má každá komponenta aspoň jedno připojené rozhraní, žádná šipka nemíří na komponentu místo na smlouvu a zakrytí kteréhokoli boxu dlaní stále nechá na obrazovce dost na to, aby šla jeho náhrada zadat. Platí-li všechno troje, diagram tvrdí něco ověřitelného a můžete skončit.

Všechny články