AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content
LLD notes

Low-Level Design · Note 2 of 9

UML Class Diagrams for LLD Interviews

Beginner · 5 min read · updated 14 November 2026

Quick answer

What is a UML class diagram?

A UML class diagram shows the classes of a design, their fields and methods, and the relationships between them. Each class is a box with three compartments: name, fields and methods, each member prefixed with its visibility. Lines between boxes show association, aggregation, composition, inheritance, realization and dependency, with multiplicity such as 1 or 0..* at the ends.

On this page
  1. The class box
  2. The six relationships
  3. Multiplicity
  4. A worked example: a library
  5. Drawing it in an interview
  6. Interview questions
  7. Common questions

A class diagram is the shared sketch of an LLD round: who the classes are, what they hold, and how they relate. Learn the notation once and you can draw any design in minutes.

The class box

  • Three compartments: name, fields, methods.
  • A member is visibility name: type; a method adds (params): returnType.
  • Visibility: + public, - private, # protected, ~ package.
  • Interfaces and abstract classes carry a stereotype: «interface», «abstract».
Anatomy of a UML class box

A class box starts with its name in the top compartment. An abstract class or interface adds a stereotype such as «interface» above the name.

0:01 / 0:12Step 1 of 4
Transcript · 4 steps

The six relationships

RelationLineMeans
Associationsolid, open arrowholds a reference
Aggregationhollow diamond at wholehas parts that live on
Compositionfilled diamond at wholeparts die with the whole
Inheritancesolid, hollow triangleis a kind of
Realizationdashed, hollow triangleimplements an interface
Dependencydashed, open arrowuses briefly
The six class relationships and how UML draws them

Association: solid line, open arrow. Read it as "a member knows the books it has".

0:01 / 0:13Step 1 of 6
Transcript · 6 steps

Multiplicity

  • Written at each end of a line: how many objects sit there.
  • 1 exactly one, 0..1 optional, 0..* or * any, 1..* at least one, 0..3 a range.
  • Read across the line: "one Member has 0..3 Loans".
  • It is a rule: the code must refuse what the diagram forbids.
Multiplicity: how many objects sit at each end
Member 1 — 0..3 Loan; asha borrows four books

Multiplicity is written at each end of a line: one Member has 0..3 Loans, and each Loan belongs to exactly 1 Member.

0:01 / 0:13Step 1 of 5
Transcript · 5 steps

A worked example: a library

Requirement: members join a library and borrow its books, at most three at a time; overdue loans are fined.

A library system's class diagram, built up

The library example starts from Library, the class the use cases enter through: members join it and borrow its books.

0:01 / 0:17Step 1 of 6
Transcript · 6 steps
  • Aggregation, not composition, where parts outlive the whole.
  • An interface (Borrowable) at the point where new kinds will arrive.
  • A dependency for helpers that keep no reference.

Drawing it in an interview

  • Start with names only; add fields and methods as use cases need them.
  • Draw only what you will discuss: skip getters, setters and constructors.
  • Put multiplicity on the lines that carry a business rule.
  • When unsure between aggregation and association, say why you chose; reasoning matters more than notation.

Interview questions

  • Aggregation or composition for a car and its engine? Composition if engines are never moved between cars in this system; aggregation if they are tracked and reused.
  • Where does the diamond go? On the whole, never the part.
  • How do you show an abstract method? In italics, or with {abstract}; in an interview, the «abstract» stereotype on the class is enough.
  • **What does 0..* next to Book mean?** Any number of books, including none, at that end.

Next: Design Patterns in LLD · Before this: Introduction to Low-Level Design

Common questions

What do the symbols +, -, # and ~ mean in a UML class diagram?

They give a member's visibility. A plus is public, a minus is private, a hash is protected (the class and its subclasses) and a tilde is package-private. A common default is private fields and public methods.

What is the difference between aggregation and composition in UML?

Both mean a whole has parts. Aggregation, a hollow diamond at the whole, means the parts can exist on their own, like members of a library. Composition, a filled diamond, means the parts are created and destroyed with the whole, like rooms of a house.

What is the difference between inheritance and realization?

Inheritance, a solid line with a hollow triangle, means a class extends another and is a kind of it. Realization, a dashed line with a hollow triangle, means a class implements an interface and promises its methods.

What does multiplicity mean in a class diagram?

Multiplicity says how many objects can sit at one end of a relationship: 1 exactly one, 0..1 optional, 0..* or * any number, 1..* at least one, or a range like 0..3. It is a rule the code must enforce.

When should I use a dependency instead of an association?

Use an association when a class keeps a reference to the other as a field. Use a dependency, a dashed arrow, when it only uses the other briefly, as a parameter, a local variable or a return value.

UML Class Diagram Relationships for LLD, Animated

UML class diagrams for low-level design interviews: class box notation, visibility, the six relationships, multiplicity and a library example built up.

What is a UML class diagram?

A UML class diagram shows the classes of a design, their fields and methods, and the relationships between them. Each class is a box with three compartments: name, fields and methods, each member prefixed with its visibility. Lines between boxes show association, aggregation, composition, inheritance, realization and dependency, with multiplicity such as 1 or 0..* at the ends.

A class diagram is the shared sketch of an LLD round: who the classes are, what they hold, and how they relate. Learn the notation once and you can draw any design in minutes.

The class box

  • Three compartments: name, fields, methods.
  • A member is visibility name: type; a method adds (params): returnType.
  • Visibility: + public, - private, # protected, ~ package.
  • Interfaces and abstract classes carry a stereotype: «interface», «abstract».
Book- isbn: String- title: String# copies: int+ isAvailable(): bool+ borrow(m: Member): Loan~ restock(n: int): voidnamefieldsmethods- private- private# protected+ public+ public~ package
Anatomy of a UML class box.
  1. A class box starts with its name in the top compartment. An abstract class or interface adds a stereotype such as «interface» above the name.
  2. The middle compartment lists fields as visibility, name, colon, type: - isbn: String is a private field holding a String.
  3. The bottom compartment lists methods with parameters and a return type. borrow(m: Member): Loan takes a Member and returns a Loan.
  4. The first character is the visibility: minus private, plus public, hash protected, tilde package. Fields private, methods public is the usual default.

The six relationships

RelationLineMeans
Associationsolid, open arrowholds a reference
Aggregationhollow diamond at wholehas parts that live on
Compositionfilled diamond at wholeparts die with the whole
Inheritancesolid, hollow triangleis a kind of
Realizationdashed, hollow triangleimplements an interface
Dependencydashed, open arrowuses briefly
MemberBookAssociationsolid line, open arrowLibraryMemberAggregationhollow diamond at the wholeLibraryShelfCompositionfilled diamond at the wholeEBookBookInheritancesolid line, hollow triangleBook«interface»BorrowableRealizationdashed line, hollow triangleFineCalcLoanDependencydashed line, open arrow
The six class relationships and how UML draws them.
  1. Association: solid line, open arrow. Read it as "a member knows the books it has".
  2. Aggregation: hollow diamond at the whole. Read it as "members outlive the library".
  3. Composition: filled diamond at the whole. Read it as "shelves die with the library".
  4. Inheritance: solid line, hollow triangle. Read it as "an e-book is a book".
  5. Realization: dashed line, hollow triangle. Read it as "Book implements Borrowable".
  6. Dependency: dashed line, open arrow. Read it as "uses a Loan only as a parameter".

Multiplicity

  • Written at each end of a line: how many objects sit there.
  • 1 exactly one, 0..1 optional, 0..* or * any, 1..* at least one, 0..3 a range.
  • Read across the line: "one Member has 0..3 Loans".
  • It is a rule: the code must refuse what the diagram forbids.
Member- name: String+ borrow(b: Book)Loan- due: Date+ close()10..3objects at run timeasha: MemberL1: DuneL2: EmmaL3: UlyssesL?: Belovedrefused: already 3
Multiplicity: how many objects sit at each end. Example: Member 1 — 0..3 Loan; asha borrows four books
  1. Multiplicity is written at each end of a line: one Member has 0..3 Loans, and each Loan belongs to exactly 1 Member.
  2. asha borrows Dune, creating loan 1. The member end says 1: this loan links to asha and to nobody else.
  3. asha borrows Emma, creating loan 2. The member end says 1: this loan links to asha and to nobody else.
  4. asha borrows Ulysses: 3 loans, the upper bound of 0..3. The diagram allows exactly this many links from one Member.
  5. A fourth borrow would break 0..3, so borrow refuses it. Multiplicity is a rule the code must enforce, not just a label.

A worked example: a library

Requirement: members join a library and borrow its books, at most three at a time; overdue loans are fined.

Library- name: String+ join(m: Member)Book- isbn: String+ isAvailable()Member- loans: Loan[]+ borrow(b: Book)Loan- due: Date+ isLate(): bool«interface»Borrowable+ isAvailable()FineCalc+ fine(l: Loan)0..*0..*10..30..*1
A library system's class diagram, built up.
  1. The library example starts from Library, the class the use cases enter through: members join it and borrow its books.
  2. Library aggregates 0..* Books (hollow diamond): a book record can outlive one library, for example when a branch closes.
  3. Library also aggregates 0..* Members. A member account exists on its own and could belong to another branch.
  4. A Loan links one Member to one Book: Member 1 to 0..3 Loan caps the loans, and each Loan points at exactly 1 Book.
  5. Book realizes the Borrowable interface (dashed line, hollow triangle), so a DVD could later be lent through the same code.
  6. FineCalc depends on Loan (dashed arrow): it only takes a Loan as a parameter and keeps no reference to it.
  • Aggregation, not composition, where parts outlive the whole.
  • An interface (Borrowable) at the point where new kinds will arrive.
  • A dependency for helpers that keep no reference.

Drawing it in an interview

  • Start with names only; add fields and methods as use cases need them.
  • Draw only what you will discuss: skip getters, setters and constructors.
  • Put multiplicity on the lines that carry a business rule.
  • When unsure between aggregation and association, say why you chose; reasoning matters more than notation.

Interview questions

  • Aggregation or composition for a car and its engine? Composition if engines are never moved between cars in this system; aggregation if they are tracked and reused.
  • Where does the diamond go? On the whole, never the part.
  • How do you show an abstract method? In italics, or with {abstract}; in an interview, the «abstract» stereotype on the class is enough.
  • **What does 0..* next to Book mean?** Any number of books, including none, at that end.

Next: Design Patterns in LLD · Before this: Introduction to Low-Level Design

Common questions

What do the symbols +, -, # and ~ mean in a UML class diagram?

They give a member's visibility. A plus is public, a minus is private, a hash is protected (the class and its subclasses) and a tilde is package-private. A common default is private fields and public methods.

What is the difference between aggregation and composition in UML?

Both mean a whole has parts. Aggregation, a hollow diamond at the whole, means the parts can exist on their own, like members of a library. Composition, a filled diamond, means the parts are created and destroyed with the whole, like rooms of a house.

What is the difference between inheritance and realization?

Inheritance, a solid line with a hollow triangle, means a class extends another and is a kind of it. Realization, a dashed line with a hollow triangle, means a class implements an interface and promises its methods.

What does multiplicity mean in a class diagram?

Multiplicity says how many objects can sit at one end of a relationship: 1 exactly one, 0..1 optional, 0..* or any number, 1.. at least one, or a range like 0..3. It is a rule the code must enforce.

When should I use a dependency instead of an association?

Use an association when a class keeps a reference to the other as a field. Use a dependency, a dashed arrow, when it only uses the other briefly, as a parameter, a local variable or a return value.

← Introduction to Low-Level Design · Design Patterns in LLD →