Archyno
UMLZáklady

Který UML diagram použít

Všech čtrnáct typů UML diagramů vedle sebe, seřazených podle otázky, na kterou odpovídají - abyste si vybrali za třicet sekund místo hodiny kreslení špatného diagramu.

9 min čteníUML 2.5.13 z 35

What types exist,and how do they relate?Who uses it,and what for?What happens,in what order?What runswhere?Class diagramUse case diagramSequence diagramDeployment diagram
The four questions that account for most real diagrams, and the diagram each one wants.

01Start from the question, not the catalogue

Fourteen diagram types is a menu, and a menu is the wrong tool when you already know what you want to say. The reliable way in is to write down the question in one sentence and let the sentence pick the diagram. Almost every real question maps onto one of four.

ElementNotationWhat it means
What is it made of?ClassTypes, their attributes and how they relate. The class diagram is the default answer to any structural question and the one whose notation the rest borrow.
Who wants what from it?Use caseActors, goals and the system boundary. A use case diagram is a scope agreement, not a design.
What happens, in what order?SequenceParticipants and the messages between them, top to bottom. Reach for a sequence diagram when the order is the thing that is hard.
What runs where?DeploymentNodes, artifacts and the paths between them. The deployment diagram is what an infrastructure or security review actually needs.

The four questions that cover most work.

02The seven structure diagrams

A structure diagram shows what the system is made of, and nothing in it changes over time. All seven reuse class-diagram notation, so the cost of the sixth is far lower than the cost of the first.

ElementNotationWhat it means
ClassEverydayTypes, attributes, operations and relationships. The one to learn first and the one you will draw most.
ObjectOccasionalOne snapshot of real instances. An object diagram is how you show that a confusing class diagram does in fact hold together.
ComponentCommonDeployable units and the interfaces they provide and require. The component diagram is the closest UML gets to an architecture picture.
DeploymentCommonNodes, artifacts, and which artifact is deployed onto which node.
PackageOccasionalNamespaces and the dependencies between them. A package diagram is how a cycle between modules becomes visible.
Composite structureRareThe internals of one classifier: parts, ports and connectors. Useful in embedded and systems work, rarely elsewhere.
ProfileRareHow UML itself is extended - stereotypes and tagged values. You read a profile diagram far more often than you draw one.

03The seven behaviour diagrams

A behaviour diagram shows what happens, in what order and under what conditions. If your question has a when in it, you are here. Four of the seven are interaction diagrams, which differ mostly in what they put on which axis.

ElementNotationWhat it means
Use caseCommonActors, goals and scope. Deliberately says nothing about how.
ActivityEverydaySteps, branches, concurrency and responsibility. The activity diagramis UML's flowchart, with real semantics attached.
State machineCommonThe lifecycle of one object: states, events and transitions. A state machine earns its place the moment a status column exists.
SequenceEverydayMessages between participants, ordered down the page.
CommunicationOccasionalThe same interaction drawn as a network, with numbered messages. A communication diagram shows who talks to whom rather than when.
TimingRareState against a time axis. A timing diagram is for when the deadline itself is the requirement.
Interaction overviewRareAn activity diagram whose nodes are whole interactions - the index page for a set of sequence diagrams.

04The four that carry the load

Most teams draw four types and read a fifth. That is not a failure of ambition - it is what happens when every diagram has to be kept true. The other ten are worth being able to read when you meet one, which is a much smaller investment than being able to draw one cold.

Reach for it when

  • Class - the domain, once, kept current. The diagram most likely to still be true a year later.
  • Sequence - the one or two flows that are genuinely hard to explain in a paragraph.
  • Activity - a process crossing teams, where the swimlane is the whole point.
  • Deployment - any system whose infrastructure is not obvious from the repository.

Reach for something else when

  • Composite structure, unless you are doing embedded or systems engineering.
  • Timing, unless a deadline in milliseconds is part of the requirement.
  • Interaction overview, unless you already have several sequence diagrams to index.
  • Profile, unless you are extending UML itself rather than using it.

If you are learning rather than choosing, the order is the same: class first, because six of the structure diagrams reuse its notation; then sequence, because it is the one people ask for by name; then activity and use case, which are cheap once you can read a guard. The symbol reference covers the vocabulary all of them share.

05When the answer is not UML at all

Three questions look like UML questions and are not. Reaching for the wrong notation costs more than reaching for the wrong diagram, because the audience cannot read it either.

ElementNotationWhat it means
A database schemaERUse an ER diagram in crow's foot notation. Tables and keys are not classes and operations.
A business processBPMNUse BPMN when business analysts are the audience or the model is destined for an engine. An activity diagram is the right answer only when the audience is engineers.
An enterprise landscapeArchiMateUse ArchiMate when the subject spans business, application and technology. UML has no vocabulary for a business capability.

06What to remember

In one line each

  1. 01Write the question in one sentence first. The sentence picks the diagram; the catalogue never does.
  2. 02Structure diagrams answer what it is made of; behaviour diagrams answer what happens. A when in the question means behaviour.
  3. 03Four types carry most real work: class, sequence, activity and deployment.
  4. 04Activity is about work and responsibility; sequence is about messages and their order.
  5. 05If the subject is a schema, a business process or an enterprise landscape, the answer is ER, BPMN or ArchiMate rather than UML.

07Časté dotazy

Který UML diagram se v praxi používá nejčastěji?

S velkým odstupem diagram tříd, za ním sekvenční diagram. Společně pokrývají většinu návrhových diskusí: z čeho se systém skládá a co se děje za běhu. Následují diagramy případů užití a aktivit, obvykle spíše při sběru požadavků než při návrhu.

Který UML diagram zobrazuje průběh procesu?

Diagram aktivit. Má akce, rozhodnutí se strážemi, rozvětvení pro souběžnost a plavecké dráhy pro odpovědnost, což je přesně slovník, který proces potřebuje. Sekvenční diagram použijte tehdy, když je podstatné, který účastník posílá kterou zprávu.

Mám použít diagram aktivit, nebo sekvenční diagram?

Zeptejte se, o čem diagram je. Pokud je o krocích procesu a o tom, kdo je za který odpovědný, použijte diagram aktivit. Pokud je o zprávách mezi konkrétními účastníky a jejich pořadí, použijte sekvenční. Aktivita je o práci, sekvence o konverzaci.

Který UML diagram zobrazuje strukturu databáze?

Přímo žádný. Nejblíže je diagram tříd a často se používá pro doménový model, ale popisuje typy a chování, ne tabulky a klíče. Na schéma použijte ER diagram v notaci vraní nohy, která byla navržena přesně k tomu.

Kolik UML diagramů potřebuje jeden systém?

Obvykle tři až čtyři, ne čtrnáct. Diagram tříd pro doménu, sekvenční pro jeden či dva náročné toky a diagram nasazení, pokud infrastruktura není zřejmá. Každý další diagram je další artefakt, který musí někdo udržovat pravdivý.

Všechny články