Last updated
UML Class Diagrams
UML class diagrams visualize the structure of object-oriented systems by showing classes, their attributes and methods, and the relationships between them. They're used in software design to plan architecture before coding and to document existing systems. The most common tool for generating class diagrams from text is Mermaid, which renders diagrams from a simple DSL.
Class Diagram Relationships
| Relationship | Symbol | Meaning |
|---|---|---|
| Association | ── | General relationship between classes |
| Inheritance | ──▷ | Child extends parent (is-a) |
| Composition | ◆── | Strong ownership (part-of, lifecycle tied) |
| Aggregation | ◇── | Weak ownership (has-a, independent lifecycle) |
| Dependency | - - ▷ | Uses another class temporarily |
| Realization | - - ▷ | Implements an interface |
Mermaid Class Diagram Syntax
classDiagram
class Animal {
+String name
+int age
+makeSound() void
}
class Dog {
+String breed
+fetch() void
}
class Cat {
+bool indoor
+purr() void
}
Animal <|-- Dog : extends
Animal <|-- Cat : extends
class Owner {
+String name
+List~Animal~ pets
+addPet(Animal) void
}
Owner "1" o-- "0..*" Animal : owns