Diagram Desk

UML class diagram relationships, examples

The three-part class box and the six UML relationships, from inheritance to dependency, with editable class diagram examples.

What is a class diagram

A class diagram is a UML picture of the classes in a program, their attributes and methods, and how classes relate. Use it to plan structure before coding or to explain existing code.

  • Object-oriented programming assignments and design documents
  • UML relationship questions in exams
  • Explaining the structure of a library or service
Shape«abstract»+color String+area() doubleCircle+radius double+area() doubleRectangle+width double+height double+area() double
Shape inheritance class diagram

Symbols and meanings

SymbolMeaning
ClassA box with name, attributes and methods.
InterfaceMarked «interface»; methods only.
InheritanceSolid line from child to parent, hollow triangle at the parent.
RealizationDashed line to the interface, hollow triangle.
CompositionFilled diamond at the whole; parts die with it.
AggregationHollow diamond at the whole; parts can live alone.
AssociationOne class knows and uses another; solid arrow.
DependencyUses another briefly (a parameter); dashed arrow.

Basis: UML 2.5 클래스 다이어그램(OMG), 객체지향 설계 수업 범위

How to draw one

  1. Split the box into name, attributes and methods.
  2. Mark visibility with + (public), - (private), # (protected).
  3. "X is a kind of Y" is inheritance: solid line, hollow triangle.
  4. Implementing an interface is realization: dashed line, hollow triangle.
  5. Parts that live and die with the whole are composition (filled diamond); parts that can exist alone are aggregation (hollow diamond).

Mermaid classDiagram: class Member { +name String / +login() bool }, Parent <|-- Child, Interface <|.. Impl, Whole *-- Part, Whole o-- Part, A --> B, A ..> B.

Common mistakes

  • The inheritance arrow starts at the parent (the triangle belongs at the parent).
  • Composition or aggregation diamonds on the part end (they belong on the whole).
  • An interface drawn with a solid inheritance line.
  • Inheritance that loops back to itself.

The editor's notation check flags these mistakes every time the picture changes.

12 class diagram examples

Draw a class diagram from scratch

All SeewolLabs tools