Chalkline / Guides / UML class diagram examples

UML class diagrams: notation and examples

A class diagram shows the building blocks of a program and how they relate. Learn the notation in five minutes and draw one from text or straight from your code.

Updated 7 November 2026 · 2 minute read

Reading a class box

Each class is a box with three parts:

  1. Name at the top, for example Order.
  2. Attributes (data) in the middle, such as +int id.
  3. Methods (actions) at the bottom, such as +total() float.

The sign in front says who can use it:

SignVisibility
+Public: anyone
-Private: only this class
#Protected: this class and its children
~Package: the same module

The lines between classes

RelationshipDrawn asMeansExample
InheritanceArrow with a hollow triangle"is a"Dog is an Animal
AssociationPlain line or arrow"uses" or "knows"Owner has Dogs
AggregationLine with a hollow diamond"has", parts can live aloneTeam has Players
CompositionLine with a filled diamond"owns", parts die with itHouse has Rooms
DependencyDashed arrow"depends on" for a momentReport uses Printer

Numbers at the ends, called multiplicity, say how many: 1, 0..1, * (many), 1..* (one or more).

Example: pets and owners

Inheritance and an association with multiplicityInheritance and an association with multiplicityAnimal+String name+int age+makeSound() voidDog+fetch() voidCat+purr() voidOwner+String email+adopt(Animal a) void1 · owns · *
Inheritance and an association with multiplicityOpen this example in Chalkline →

The text behind it:

classDiagram
  class Animal {
    +String name
    +int age
    +makeSound() void
  }
  class Dog {
    +fetch() void
  }
  Animal <|-- Dog
  Owner "1" --> "*" Animal : owns

Relationship arrows in text

A <|-- B     B inherits from A
A *-- B      A is composed of B
A o-- B      A aggregates B
A --> B      A is associated with B
A ..> B      A depends on B
A "1" --> "*" B : label    with multiplicity and a label

From code to a class diagram

If the classes already exist in code, you do not have to type them. Chalkline reads Python, Java, TypeScript, C++ and Go and draws a class diagram of the file: classes, fields, methods and inheritance. Open Diagram as text → From code, paste the file and choose Classes.

Draw classes from your codePaste a file and pick Classes in the list
Open the example

Tips for clear class diagrams

  • Show only the classes that matter for the point you are making.
  • Leave out getters, setters and obvious fields.
  • Put parent classes above their children so inheritance arrows point up.
  • One diagram per feature or module is easier to read than one for the whole system.

Draw yours for free in Chalkline, then export to SVG, PDF, PowerPoint or TikZ for a report. For database tables instead of classes, see SQL to ER diagram.