Artificial Intelligence & Data Science is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

UML use case and class diagrams

Clear, exam-focused notes on UML use case and class diagrams: definitions, precise notation, how to draw diagrams, worked examples (ATM and Library), common mistakes and exam tips.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Use case and class diagrams are two fundamental UML views used by engineers to capture functional requirements and the static structure of a system. Use case diagrams help communicate what the system must do (requirements and actors); class diagrams drive design and implementation (data structures, relationships, and interfaces).

Key ideas

Definition and purpose

  • UML (Unified Modeling Language): a standardized general-purpose visual language to specify, construct and document the artifacts of software systems. Use it to communicate between stakeholders, and to guide design and implementation.
  • Use case: a use case is a description of a set of interactions between actors and the system that yields an observable result of value. (Assumption: use cases capture functional requirements at a user-goal level; they do not show internal algorithmic steps.) A scenario is one specific sequence (instance) of a use case.
  • Actor: an entity (human, external system or time/event) that interacts with the system. Actors are not part of the system boundary.
  • System boundary: a labeled box that defines what is inside the system (use cases) and what is outside (actors).
  • Class: a blueprint describing a set of objects that share the same attributes (data) and operations (behavior). Classes model the static structure of the system.
  • Attribute: a named property of a class with a type and optionally a default value.
  • Operation: a named function/method that the class can perform; defines signature (parameters and return type).
  • Association: a structural relationship between classes showing links between their instances. Associations may have multiplicities and role names.
  • Multiplicity: a constraint on how many instances of a class may relate to an instance of another class (examples: 1, 0..1, * or 0..*, 1..*).
  • Aggregation: a weak whole-part relationship represented by a hollow diamond at the whole end. Aggregation implies a part may exist independently of the whole.
  • Composition: a strong whole-part relationship with ownership; represented by a filled diamond at the whole end. In composition, parts typically have the same lifetime as the whole. A part belongs to at most one whole at a time.
  • Generalization (inheritance): a relationship where a subclass inherits structure and behavior from a superclass; draw as a solid line with a hollow triangle arrow pointing to the superclass.
  • Dependency: a weaker relationship where one element depends on another (use a dashed arrow).
  • Interface: a named set of operations without implementation; shown as a circle (lollipop) or a class-like box with «interface». Classes realize interfaces (dashed line with hollow triangle).

Use case diagram elements and rules (how to draw)

  • Draw a rectangle labelled with the system name — this is the system boundary.
  • Outside the rectangle, draw actors as stick figures or rectangles with the «actor» keyword. Label each actor (e.g., Customer, Admin, PaymentGateway).
  • Inside the rectangle, draw use cases as ovals; label each with a short verb-noun phrase (e.g., "Withdraw Cash").
  • Connect actors to the use cases they participate in with solid lines (associations).
  • Use these use case relationships:
    • <<include>>: a directed dashed arrow with label <<include>> from a base use case to the included use case. Use when a use case always uses behaviour of another use case (reusable fragment).
    • <<extend>>: a directed dashed arrow with label <<extend>> from an extension use case to the base; used when the extension may add behavior conditionally. Optionally, list extension points on the base use case to indicate where the additional behavior is inserted.
  • Do not show internal algorithms or control flow in a use case diagram; show only actors, goals and relationships.

Class diagram rules and how to draw

  • For each class draw a rectangle with three compartments: 1) class name (centered), 2) attributes (one per line), 3) operations (one per line).
  • Attribute syntax: visibility name : Type = default (visibility: +, -, #).
  • Operation syntax: visibility name(parameter: Type) : ReturnType.
  • Draw associations (solid lines) between classes; label with role names and multiplicity near each end.
  • For inheritance draw a solid line with a hollow triangle pointing to the superclass.
  • For composition draw a filled diamond at the whole class end; for aggregation draw a hollow diamond at the whole end.
  • Show visibility for attributes and operations; private data should be -, public APIs +. Use italics for abstract class and operation names; underline static (class) attributes/operations; show navigability with open arrowheads on association ends if needed.

Assumptions universities expect

  • Use cases are written for external goals; they are not equivalent to UI screens.
  • Class diagrams represent static relationships; dynamic behaviour goes in sequence/state/activity diagrams.
  • Multiplicity 1 means exactly one, * means zero or more.

Exact statements students must remember (form-like)

  • Definition: A use case describes sequences of actions between actors and the system that produce an observable result of value. (In the textual specification, include preconditions and postconditions.)
  • Definition: A class groups attributes and operations; an object is an instance of a class.

If an exam asks for a diagram, draw as described above and label every actor, use case, class name, multiplicity and relationship type.

Formulas

Attribute syntax: visibility name : Type = default — visibility (+ public, - private, # protected), name is identifier, Type is datatype, default is optional value. Applies when listing attributes in class diagrams. Operation syntax: visibility name(param: Type) : ReturnType — param is parameter list. Use to define method signatures. Multiplicity examples: 1, 0..1, *, 1..* — 1 = exactly one, 0..1 = zero or one, * or 0..* = zero or more, 1..* = one or more. Apply at association ends. Association: ClassA — ClassB (roleA [multiplicityA], roleB [multiplicityB]) — shows structure linking instances. Composition: ClassA ◆— ClassB (filled diamond on ClassA end) — ClassA is whole, ClassB is part; part lifetime tied to whole. Aggregation: ClassA ◇— ClassB (hollow diamond on ClassA end) — weaker whole-part relationship. Generalization: Subclass ─▷ Superclass (open triangle arrow to superclass) — subclass inherits from superclass. Dependency: Client -- - -> Supplier (dashed arrow) — client depends on supplier.

Worked examples

Example 1 — Use case diagram: ATM Withdraw and Balance check Problem statement: Draw a use case diagram for an ATM where a Customer can Withdraw Cash and Check Balance. The Bank (remote system) is contacted for authentication and funds. Include authentication as a reusable behaviour. Steps and diagram to draw:

  1. Draw a rectangle labeled "ATM System" (system boundary).
  2. Outside, draw two actors: stick figure labelled Customer, and stick figure labelled Bank (external system).
  3. Inside the rectangle, draw three ovals labelled: "Authenticate", "Withdraw Cash", "Check Balance".
  4. Connect Customer to "Withdraw Cash" and "Check Balance" with solid lines.
  5. Draw a dashed arrow labelled <<include>> from both "Withdraw Cash" and "Check Balance" to "Authenticate" (because authentication is reused and always required).
  6. Connect "Authenticate" to Bank with a solid line (the ATM system interacts with the bank outside). Answer summary (what examiner expects): clear system boundary, actor positions outside, correct use of <<include>> for authentication, associations labelled if required.

Example 2 — Class diagram: Library loan model (numerical-style clarity) Problem statement: Model classes Book, Borrower, Loan, Librarian. A Book may have many Loans over time; a Loan links one Book to one Borrower; a Librarian issues Loans. Step-by-step model and multiplicities:

  1. Draw class rectangles with compartments.
    • Book
      • -isbn : String
      • -title : String
      • -author : String
      • +isAvailable() : Boolean
    • Borrower
      • -borrowerId : String
      • -name : String
      • +borrow(book : Book) : Loan
    • Loan
      • -loanId : String
      • -startDate : Date
      • -dueDate : Date
      • +isOverdue() : Boolean
    • Librarian
      • -staffId : String
      • +issueLoan(b : Borrower, bk : Book) : Loan
  2. Associations and multiplicities:
    • Borrower 1 — 0..* Loan (one borrower can have zero or many loans)
    • Loan 1 — 1 Book (each loan is for exactly one book)
    • Librarian 1 — 0..* Loan (librarian issues many loans); Loan 1 — 1 Librarian (each loan is issued by exactly one librarian)
    • Book 1 — 0..* Loan (book may appear in many past loans; if copies are modelled, include class Copy)
  3. If modelling physical copies, create class Copy with attribute copyId and relation Copy 1 — 0..* Loan. Answer expected: rectangles with correct visibility, multiplicities, association names optional, composition not used here (loans do not own books), clear operations.

Example 3 — Converting a use case to classes (short model answer style) Question: From the use case "Place Order" in an online shop, list likely candidate classes. Model answer (full marks): Candidate classes: Order (attributes: orderId, date, status), Customer (customerId, address), Product (productId, price), Cart (items), Payment (amount, method), OrderItem (quantity, price). Show relationships: Customer 1 — 0..* Order; Order 1 — 1..* OrderItem; OrderItem 1 — 1 Product; Order 1 — 0..1 Payment.

Common mistakes

  • Using <<extend>> where <<include>> is correct: remember include = always used (reusable), extend = optional/conditional.
  • Confusing aggregation and composition or using them interchangeably; composition implies ownership and lifetime coupling.
  • Forgetting multiplicities or writing nonsensical ones (e.g., 1..1 when 1 suffices) or mismatching ends.
  • Omitting visibility for attributes and operations when asked to show design-level diagrams.
  • Mixing up interface realization notation (dashed line with hollow triangle) with inheritance (solid line with hollow triangle).
  • Treating a use case as a sequence of method calls (use cases describe interactions/goals, not code-level steps).

For your exam

Types of questions

  • Definitions and short notes: define UML, use case, actor, class, association, composition, aggregation.
  • Draw diagrams: draw a use case or class diagram given a short system description.
  • Convert: map use cases to classes or produce class attributes/operations from requirements.
  • Explain relationships: justify multiplicities and whether composition/aggregation applies. What a full-marks answer includes
  • For diagrams: correct elements (actors/classes), correct symbols (diamond triangle, dashed/solid lines), multiplicities and role names where relevant, clear labels and a system boundary for use cases.
  • For theory: precise definitions, mention assumptions, and short examples (one-line) showing understanding.
  • For conversions: show reasoning steps — identify nouns (candidate classes), verbs (candidate operations), then refine with multiplicities and associations.

Quick check

  1. What symbol shows composition in a class diagram and what does it mean about lifetime?
  2. In a use case diagram, where should actors be drawn relative to the system boundary?
  3. Write the attribute syntax for a private integer count with default 0. Answers: 1) Filled diamond at the whole end; it means parts are owned and typically share the lifetime of the whole. 2) Outside the system boundary. 3) - count : int = 0

Note to reviewer: I have tried to be precise with UML notation and exam-style instructions. Where I am unsure I list items in the verify field below — please check those.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?