UML class diagram (D2)

D2 has a class shape with typed fields and methods, so a class diagram does not need a second language.


#What this example shows

  • shape: class, with fields and methods declared inline.

  • Visibility markers on members.

  • Relationship arrows with labels.


#A worked example

Open it, edit it, or copy the source below.

UML class diagram (D2)

The source, which you can paste into a new diagram and edit:

direction: down

Payment: {
  shape: class

  \#value: Money
  \#reference: string
  +authorise(): bool
  +capture(): Receipt
}

CardPayment: {
  shape: class

  -last4: string
  -scheme: string
  +authorise(): bool
}

BankTransfer: {
  shape: class

  -iban: string
  +authorise(): bool
}

Order: {
  shape: class

  +id: uuid
  +status: OrderStatus
  +total(): Money
}

Payment <- CardPayment: extends
Payment <- BankTransfer: extends
Order -> Payment: settled by

#Making it your own

  • Prefix members with +, - or # for public, private and protected.

  • A trailing (): type marks a method rather than a field.

  • For full UML with stereotypes and packages, PlantUML goes further.



Nesting is the whole idea.