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.
You can also use UML-style prefixes to indicate field/method visibility.
Here's an example with differing visibilities and more complex types: