Loading…
Loading…
The class header (alias uml) switches to single-column UML class boxes,
connected with UML relationship arrowheads instead of the crow's-foot notation of
an ERD. It shares that family's block grammar: a
class is a named block of members, and a line of dashes inside it is a
compartment divider.
--- (two or more dashes on their own line) draws a compartment divider.
Members above the first divider are attributes; those below are methods.+, -, #, or ~ sets visibility (public, private, protected,
or package), drawn as that glyph.name type, written the way the code writes it: a method may
list its parameters (+add(s: Shape) void), and a type may hold spaces
(Map<string, Shape>, Shape | null). A method written without parentheses
shows as name().The block must span lines: the opening { and closing } sit on their own
lines, one member per line between them. (An inline Dog { +fetch() void } on a
single line is not parsed as a class.) A class with no members is written
Runnable { }.
Each relationship has its own connector and UML arrowhead. Every connector has a
mirror spelling (<|-- and --|>, *-- and --*, …) so you can write the ends
in either order; the marker always lands on the correct end.
| Connector | Relationship | Arrowhead |
|---|---|---|
--|> | inheritance (extends) | hollow triangle on the parent |
..|> | realization (implements) | dashed, hollow triangle |
*-- | composition | filled diamond on the whole |
o-- | aggregation | hollow diamond on the whole |
..> | dependency (uses) | dashed open arrow |
Both ends of a relationship must be declared classes. A plain -> (or a
cardinality like 1:N) stays a normal ERD relation, so one diagram can mix UML
relationships with crow's-foot links.
Two larger models round this out. A small domain model first: a payment hierarchy with an interface, composition, and a dependency.
A layered service architecture expressed as classes and dependencies.
A group { … } block wraps classes in a labelled container — a UML namespace or
package, and the same word the graph families use.
Members are laid out together inside their own frame, so the packaging survives
instead of the boxes scattering across the diagram.
Mermaid's namespace Foo { … } imports straight onto this, so a packaged class
diagram keeps its packages. Nesting is flat: a namespace inside a namespace is
folded into its parent rather than drawn as a frame within a frame.