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.
Visibilities
You can also use UML-style prefixes to indicate field/method visibility.
visiblity 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:
