UML Classes
Basics
D2 fully supports UML Class diagrams. Here's a minimal example:
Each key of a class
shape defines either a field or a method.
The value of a field key is its type.
Any key that contains (
is a method, whose value is the return type.
A method key without a value has a return type of void.
If you'd like to use a reserved keyword, wrap it in quotes.
Visibilities
You can also use UML-style prefixes to indicate field/method visibility.
visibility prefix | meaning |
---|---|
none | public |
+ | public |
- | private |
# | protected |
See https://www.uml-diagrams.org/visibility.html
Here's an example with differing visibilities and more complex types: