Class diagram (PlantUML)

PlantUML class diagrams support the whole UML vocabulary, including packages, interfaces and stereotypes, which is where they go beyond the lighter alternatives.


#What this example shows

  • Packages, which group related classes.

  • An interface with a realisation arrow.

  • Visibility markers and abstract methods.


#A worked example

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

Class diagram (PlantUML)

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

@startuml
skinparam classAttributeIconSize 0

package "domain" {
  interface Payable {
    +amount(): Money
  }

  abstract class Payment {
    #Money value
    +{abstract} authorise(): boolean
    +reference(): String
  }

  class CardPayment {
    -String last4
    -String scheme
    +authorise(): boolean
  }

  class BankTransfer {
    -String iban
    +authorise(): boolean
  }

  class Order {
    +UUID id
    +OrderStatus status
    +total(): Money
  }
}

package "infrastructure" {
  class PaymentGateway <<adapter>> {
    +send(Payment): Receipt
  }
}

Payable <|.. Payment
Payment <|-- CardPayment
Payment <|-- BankTransfer
Order "1" o-- "0..*" Payment
PaymentGateway ..> Payment : uses
@enduml

#Making it your own

  • Set skinparam classAttributeIconSize 0 to replace the coloured icons with plain visibility markers.

  • Use <<stereotype>> to mark adapters, services and value objects.

  • Draw the classes under discussion. A whole-model diagram helps nobody.



Verbose, stable, and it draws almost everything.