Skip to main content

PlantUML Class Diagrams

This page tests the English A11y descriptions for class diagrams.

Simple class diagram with 1 class

WordList class

PlantUML source for "WordList class"
@startuml
class WordList {
-words : String[]
+sort() : void
}
@enduml

Class diagram with 1 class(es) and 0 relation(s).

Classes:

  • Class WordList with:
    • public method 'sort', without parameters, return type void
    • private attribute 'words' of type String Array

Class diagram with 3 classes and relationships

Strategy Pattern

PlantUML source for "Strategy Pattern"
@startuml
interface SortStrategy {
+sort(words: String[]) : void
}

class WordList {
-words : String[]
+sort() : void
}

class MergeSort {
+sort(words: String[]) : void
}

WordList --> SortStrategy : currentStrategy
MergeSort ..|> SortStrategy
@enduml

Class diagram with 3 class(es) and 2 relation(s).

Classes:

  • Interface SortStrategy with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes
  • Class WordList with:
    • public method 'sort', without parameters, return type void
    • private attribute 'words' of type String Array
  • Class MergeSort with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes

Relations:

  • WordList has an association-relationship named 'currentStrategy' with SortStrategy
  • MergeSort implements interface SortStrategy

Extended class diagram with 5 classes and 4 relationships

Extended Strategy Pattern

PlantUML source for "Extended Strategy Pattern"
@startuml
class WordList {
-words : String[]
+sort() : void
+setSortStrategy(strategy : SortStrategy) : void
}
interface SortStrategy {
+sort(words : String[]) : void
}
class MergeSort {
+sort(words : String[]) : void
}
class ShellSort {
+sort(words : String[]) : void
}
class QuickSort {
+sort(words : String[]) : void
}
WordList --> "1" SortStrategy : -currentStrategy
MergeSort ..|> SortStrategy
ShellSort ..|> SortStrategy
QuickSort ..|> SortStrategy
note right of WordList
public void sort() {
currentStrategy.sort(words);
}
end note
@enduml

Class diagram with 5 class(es) and 4 relation(s).

Classes:

  • Class WordList with:
    • public method 'sort', without parameters, return type void
    • public method 'setSortStrategy', with parameter(s) 'strategy' of type SortStrategy, return type void
    • private attribute 'words' of type String Array
  • Interface SortStrategy with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes
  • Class MergeSort with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes
  • Class ShellSort with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes
  • Class QuickSort with:
    • public method 'sort', with parameter(s) 'words' of type String[], return type void
    • no attributes

Relations:

  • WordList has an association-relationship named '-currentStrategy' with SortStrategy, multiplicity 1
  • MergeSort implements interface SortStrategy
  • ShellSort implements interface SortStrategy
  • QuickSort implements interface SortStrategy

Screen reader text (English):

Class diagram with 5 classes and 4 relationships.

Classes:

  • Class WordList with:
    • Private attribute words of type String Array
    • Public method sort, without parameters, return type void
    • Public method setSortStrategy with parameter strategy of type SortStrategy, return type void
  • Interface SortStrategy with public method sort with parameter words of type String Array, return type void
  • Class MergeSort with public method sort with parameter words of type String Array, return type void
  • Class ShellSort with public method sort with parameter words of type String Array, return type void
  • Class QuickSort with public method sort with parameter words of type String Array, return type void Relations:
  • WordList has an association-relationship named 'currentStrategy' with SortStrategy, multiplicity 1
  • MergeSort implements interface SortStrategy
  • ShellSort implements interface SortStrategy
  • QuickSort implements interface SortStrategy Notes:
  • At class WordList: "The sort method calls currentStrategy.sort with words as parameter"

Simple class diagram without Out loud button

This diagram has the Out loud button hidden via the hideSpeakButton flag, demonstrating per-diagram control over the speak button.

WordList class (no speak button)

PlantUML source for "WordList class (no speak button)"
@startuml
class WordList {
-words : String[]
+sort() : void
}
@enduml

Class diagram with 1 class(es) and 0 relation(s).

Classes:

  • Class WordList with:
    • public method 'sort', without parameters, return type void
    • private attribute 'words' of type String Array

Simple class diagram with hidden source

This diagram uses the hideSource flag. The source tab is hidden, while the natural language tab (including the Out loud button) remains available.

WordList class (hidden source)

"WordList class (hidden source)" in natural language

Class diagram with 1 class(es) and 0 relation(s).

Classes:

  • Class WordList with:
    • public method 'sort', without parameters, return type void
    • private attribute 'words' of type String Array

Visual mode toggle with stereotypes and auto legend

This test case validates three things for PlantUML class diagrams:

  • For devs / Simpler visual mode toggle
  • custom stereotypes (for example Entity and Value Object) are hidden in Simpler mode
  • auto-generated legend is shown when showDiagramLegend is enabled
  • advanced relation types are present for testing: inheritance, realization, dependency, composition, and aggregation

Domain model visual modes

PlantUML source for "Domain model visual modes"
@startuml
top to bottom direction

interface PaymentPort

abstract class Order <<Aggregate Root>> {
+id : UUID
+orderNumber : String
+total : Money
}

class SpecialOrder <<Entity>> {
+discountCode : String
}

class Customer <<Entity>> {
+id : UUID
+name : String
}

class OrderLine <<Entity>> {
+id : UUID
+quantity : int
}

class StripePaymentAdapter <<Service>> {
+authorize(amount : Money) : boolean
}

class Money <<Value Object>> {
+amount : Decimal
+currency : String
}

Order <|-- SpecialOrder : inheritance
PaymentPort <|.. StripePaymentAdapter : realization
Order ..> PaymentPort : dependency
Order "1" *-- "*" OrderLine : composition
Order "1" o-- "1" Customer : aggregation
Order --> Money : totalAmount
@enduml

Class diagram with 8 class(es) and 6 relation(s).

Classes:

  • Interface PaymentPort without methods and attributes
  • Abstract class Order <> with:
    • public attribute 'id' of type UUID
    • public attribute 'orderNumber' of type String
    • public attribute 'total' of type Money
    • no methods
  • Class SpecialOrder with stereotype Entity with:
    • public attribute 'discountCode' of type String
    • no methods
  • Class Customer with stereotype Entity with:
    • public attribute 'id' of type UUID
    • public attribute 'name' of type String
    • no methods
  • Class OrderLine with stereotype Entity with:
    • public attribute 'id' of type UUID
    • public attribute 'quantity' of type int
    • no methods
  • Class StripePaymentAdapter with stereotype Service with:
    • public method 'authorize', with parameter(s) 'amount' of type Money, return type boolean
    • no attributes
  • Class Money with stereotype Value Object with:
    • public attribute 'amount' of type Decimal
    • public attribute 'currency' of type String
    • no methods
  • Class Order without methods and attributes

Relations:

  • SpecialOrder extends Order
  • StripePaymentAdapter implements interface PaymentPort
  • Order has a dependency to PaymentPort
  • Order has a composition-relationship named 'composition' with OrderLine, multiplicity 1 to *
  • Order has an aggregation-relationship named 'aggregation' with Customer, multiplicity 1 to 1
  • Order has an association-relationship named 'totalAmount' with Money

Domain model visual modes

Reverse diamond notation (--o and --*)

This example verifies that reverse-direction diamond syntax is parsed correctly and still shown as advanced relations in For devs mode.

Reverse diamond notation

PlantUML source for "Reverse diamond notation"
@startuml
top to bottom direction

class Warehouse <<Entity>> {
+id : UUID
+locationCode : String
}

class StorageBin <<Entity>> {
+id : UUID
+label : String
}

class Pallet <<Entity>> {
+id : UUID
+barcode : String
}

StorageBin "*" --o "1" Warehouse : partOfWarehouse
Pallet "*" --* "1" StorageBin : packedInBin
@enduml

Class diagram with 3 class(es) and 2 relation(s).

Classes:

  • Class Warehouse with stereotype Entity with:
    • public attribute 'id' of type UUID
    • public attribute 'locationCode' of type String
    • no methods
  • Class StorageBin with stereotype Entity with:
    • public attribute 'id' of type UUID
    • public attribute 'label' of type String
    • no methods
  • Class Pallet with stereotype Entity with:
    • public attribute 'id' of type UUID
    • public attribute 'barcode' of type String
    • no methods

Relations:

  • Warehouse has an aggregation-relationship named 'partOfWarehouse' with StorageBin, multiplicity 1 to *
  • StorageBin has a composition-relationship named 'packedInBin' with Pallet, multiplicity 1 to *

Reverse diamond notation