A class diagram describes the structure of a system by showing its building blocks — called classes — and the relationships between them. Each class lists its attributes (the data it holds) and methods (the actions it can perform). Lines between classes show how they are related: one book can have many loans, one member can take out many loans.
Class diagrams are widely used in software design, but they are equally useful for modelling anything with well-defined categories and relationships — a library, a recipe collection, a product catalogue.
classDiagram
class Book {
+String title
+String author
+String isbn
+isAvailable() bool
}
class Member {
+String name
+String email
+borrowBook()
+returnBook()
}
class Loan {
+Date borrowedOn
+Date dueDate
+isOverdue() bool
}
Member "1" --> "0..*" Loan : takes out
Book "1" --> "0..*" Loan : recorded in
The multiplicity labels (such as 1 and 0..*) describe how many of each thing can be involved — one member can have zero or more loans, but each loan belongs to exactly one member.