Class Diagram

Source: PlantUML: Class Diagramarrow-up-right Digest Date: January 15, 2023

Note: The UML preview of this documentation is powered by mermaid, some PlantUML symbols are not supported by mermaid(e.g. #--), so I didn't record these special symbols.

1. Declaring Element

declaring-elements

Note: protocol and struct was added in PR-1028arrow-up-right.

2. Relations between Classes

Relations between classes are defined using the following symbols :

Type
Symbol
Drawing

Extension

`<

--`

Composition

*--

sym02

Aggregation

o--

sym03

It is possible to replace -- by .. to have a dotted line.

Knowing those rules, it is possible to draw the following drawings:

Source:

Preview by using mermaid:


Source:

Preview by using mermaid:

3. Label on Relations

It is possible to add a label on the relation, using : , followed by the text of the label.

For cardinality, you can use double-quotes "" on each side of the relation.

Source:

Preview by using mermaid:

You can add an extra arrow pointing at one object showing which object acts on the other object, using < or > at the begin or at the end of the label.

Source:

Preview by using mermaid:

Warning: This feature is not fully supported by mermaid.

4. Using non-letters in element names and relation labels

Seems not so useful, omit for now.

5. Adding methods

To declare fields and methods, you can use the symbol : followed by the field's or method's name.

The system checks for parenthesis to choose between methods and fields.

Source:

Preview by using mermaid:

It is also possible to group between brackets {} all fields and methods.

Note that the syntax is highly flexible about type/name order.

Source:

Preview by using mermaid:

You can use {field} and {method} modifiers to override default behaviour of the parser about fields and methods.

Source:

Preview by using mermaid:

Warning: This feature is not supported by mermaid.

6. Defining visibility

Last updated