Symboly UML diagramu tříd
Každá šipka, kosočtverec a přerušovaná čára, kterou diagram tříd může nést, nakreslená vedle svého významu - stránka, kterou si necháte otevřenou při kontrole značky.
6 min čteníUML 2.5.15 z 28
01The six relationships
| Element | Notation | What it means |
|---|---|---|
| Association | The two classes know about each other. The default, and the right answer far more often than the ones below it. | |
| Generalization | Hollow triangle at the parent. The child is a kind of the parent and can stand in wherever the parent is expected. | |
| Realization | Dashed, hollow triangle at the interface. The class provides what the interface declares, without inheriting state. | |
| Composition | Filled diamond at the whole. The part belongs to exactly one whole and is deleted with it. | |
| Aggregation | Hollow diamond at the whole. The part can be shared and outlives the whole. Carries no other formal meaning. | |
| Dependency | Dashed, open arrow. One class uses another without holding a reference to it - a parameter, a return type, a static call. |
The rule that makes these memorable is that the decorated end is the end that matters: the triangle points at the more general classifier, the diamond sits on the owning whole, and the open arrow points at the thing being used. If you can remember which end carries the mark, you can usually reconstruct the meaning.
02Inside the box: visibility, types and multiplicity
A class box is a name band with up to two compartments under it: attributes, then operations. Both are optional, and a box that is only a name is perfectly legal - usually the right thing on a diagram about relationships.
| Element | Notation | What it means |
|---|---|---|
| Public | + name: String | Visible to everything. What an interface's members always are. |
| Private | - id: UUID | Visible only inside the class. The default on most design diagrams. |
| Protected | # state: Status | Visible to the class and its subtypes. |
| Package | ~ cache: Map | Visible inside the owning package. Rare in practice. |
| Static | underlined | Belongs to the classifier rather than to an instance. |
| Abstract | italic | The class or operation has no implementation. Often written «abstract» instead, where italics would not survive a whiteboard. |
Multiplicity is written at the end of a relationship, and the syntax is small: 1 exactly one, 0..1 optional, * or 0..* any number including none, 1..* at least one, and 2..5 a genuine range. A missing multiplicity means unspecified rather than one, which is why leaving it blank is a gap and not a default.
03Guillemets, and the rest
Text in guillemets - «interface», «enumeration», «entity» - is a stereotype: an extension of the standard vocabulary that says what kind of thing this classifier is beyond "class". A handful are defined by UML itself; the rest come from a profile, which is the mechanism for inventing your own without leaving the language.
Two more marks are worth recognising. A note is a rectangle with a folded corner, attached by a plain dashed line, and it carries a constraint or a comment - anything in curly braces inside it, like {ordered} or {total >= 0}, is a constraint the model claims to hold. And a role name written near an association end names what that end is called from the other side, which is worth adding whenever the class name alone does not say it - manager and reports on the two ends of an association between Employee and Employee, for instance.
In one line each
- 01The decorated end is the end that matters: triangle at the parent, diamond at the whole, arrow at the used.
- 02Hollow triangle is generalization, dashed hollow triangle is realization.
- 03Filled diamond means deleted with the whole; hollow means shared and surviving.
- 04A blank multiplicity means unspecified, not one - it is a gap in the diagram.
- 05Guillemets mark a stereotype; the ones outside UML's own set come from a profile.
To see all of this on real models, read the worked examples; for the reasoning behind the marks rather than the marks themselves, the class diagram article.
04Časté dotazy
Co znamenají šipky v UML diagramu tříd?
Dutý trojúhelník je generalizace a přerušovaný realizace; plný kosočtverec je kompozice a dutý agregace; plná čára je asociace a přerušovaná otevřená šipka závislost. Hlava je v každém případě na obecnějším nebo vlastnícím konci.
Jaký je rozdíl mezi plným a dutým kosočtvercem?
Plný kosočtverec je kompozice, tedy část se maže spolu s celkem a patří právě jednomu celku. Dutý kosočtverec je agregace, tedy část může být sdílená a celek přežije. Agregace v UML 2.5.1 nenese kromě tohoto čtení žádnou formální sémantiku.
Co znamenají plus, minus a mřížka před atributem?
Jsou to značky viditelnosti: plus je veřejné, minus soukromé, mřížka chráněné a vlnovka balíčkové. Patří na návrhový diagram, kde je předmětem struktura kódu, a na doménovém modelu se obvykle vynechávají, protože o byznisu neříkají nic.
Související články