PlantUML Class Diagram: Inheritance and Interfaces

Build class diagrams with inheritance hierarchies, interfaces, and abstract classes in PlantUML. Learn relationship arrows, visibility modifiers, and stereotypes.

Class Diagrams

Detailed Explanation

Class Diagrams with Inheritance in PlantUML

Class diagrams document the static structure of a system. They show classes, their attributes and methods, and the relationships between them.

Basic Class Definition

@startuml
class User {
  -id: UUID
  -email: String
  -passwordHash: String
  +login(email, password): Boolean
  +logout(): void
  #validateEmail(email): Boolean
}
@enduml

Visibility Modifiers

Symbol Meaning
+ Public
- Private
# Protected
~ Package-private

Inheritance and Implementation

abstract class Shape {
  +area(): double
  +perimeter(): double
}

interface Drawable {
  +draw(canvas: Canvas): void
}

class Circle extends Shape implements Drawable {
  -radius: double
  +area(): double
  +perimeter(): double
  +draw(canvas: Canvas): void
}

The <|-- arrow represents inheritance (solid line, closed triangle). The ..|> arrow represents interface implementation (dashed line, closed triangle).

Relationship Types

Arrow Relationship
<|-- Inheritance (extends)
..|> Implementation (implements)
*-- Composition (strong ownership)
o-- Aggregation (weak ownership)
--> Association (uses)
..> Dependency (depends on)

Composition vs Aggregation

class Car {
  +start(): void
}
class Engine
class Passenger

Car *-- Engine : composition
Car o-- Passenger : aggregation

A car owns its engine (composition — engine cannot exist without the car), but contains passengers (aggregation — passengers exist independently).

Use Case

Designing object-oriented systems, documenting domain models for DDD projects, creating API design specs from class hierarchies, and generating architecture documentation for code reviews.

Try It — PlantUML Editor

Open full tool