Class diagrams: 6 UML relationship arrows

Class diagrams: 6 UML relationship arrows

puml.online

简介 / Introduction

Class diagrams are a core part of UML, describing the static relationships between classes in a system. Both PlantUML and Mermaid make it easy to draw the six most common relationship types: Association, Aggregation, Composition, Generalization, Dependency, and Realization.


PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@startuml
hide circle
skinparam classAttributeIconSize 0

class Driver
class Car
class Engine

' Association
Driver "1" -- "1" Car : drives >

' Aggregation
Car o-- "1" Engine : has >

' Composition
Car *-- "1..4" Wheel : has >

' Generalization
Sedan --|> Car

' Dependency
Car ..> Driver : creates

' Realization
ICruiseControl <|.. CruiseControl

class ICruiseControl
class CruiseControl
@enduml

Mermaid 版

1
2
3
4
5
6
7
8
9
10
11
12
13
classDiagram
class Driver
class Car
class Engine
class ICruiseControl
class CruiseControl

Driver "1" -- "1" Car : drives
Car o-- "1" Engine : has
Car *-- "1..4" Wheel : has
Sedan --|> Car
Car ..> Driver : creates
ICruiseControl <|.. CruiseControl

对比 / Side-by-side

Relationship PlantUML arrow Mermaid arrow
Association -- --
Aggregation o-- o--
Composition *-- *--
Generalization --|> --|>
Dependency ..> ..>
Realization <|.. <|..

小结 / Wrap-up

PlantUML and Mermaid use nearly identical arrows for class-diagram relationships, making it easy to switch between them. Solid lines (--) denote structural relationships while dotted lines (..) denote dynamic dependencies. Arrow direction points toward the depended-upon element: composition beats aggregation beats plain association.

  • Title: Class diagrams: 6 UML relationship arrows
  • Author: puml.online
  • Created at : 2026-09-01 09:00:00
  • Updated at : 2026-09-01 01:06:36
  • Link: https://puml.online/blog/class-diagram-relationships-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Class diagrams: 6 UML relationship arrows