Skip to main content

Use Case Diagrams — Who Does What

Editorial

Introduction

Before you design the classes of a system, it helps to answer a simpler question: who uses this system, and what can each of them do with it? A use case diagram answers that question on one page. It shows the actors, the people and outside systems that use the system, and the use cases, the things the system does for them.

UML defines a use case as a promise of something useful: "Each UseCase specifies a unit of useful functionality that the subject provides to its users (i.e., a specific way of interacting with the subject)." The subject is the system the diagram is about. A use case says what the system does for its users and says nothing of how it is built inside: "UseCases define the offered Behaviors of the subject without reference to its internal structure." That is a job for the class diagram from Class Diagrams — Structure of Your System and for the sequence diagrams that follow it.

A use case diagram works like the table of contents of a book. It lists what is there and who it is for, and it leaves the inside of each chapter to other pages. This page draws it for the library's lending system, the same system as the class diagram.

The Four Elements

A use case diagram has four kinds of element.

Actors stand outside the system and use it. UML calls an actor a role: "An Actor models a type of role played by an entity that interacts with the subjects of its associated UseCases (e.g., by exchanging signals and data). Actors may represent roles played by human users, external hardware, or other systems." So an actor can be a member or a librarian, and it can also be another system, such as the service that sends the library's emails, or a timer that starts something at a set time. Because an actor is a role, one person can play several actors: "a single physical instance may play the role of several different Actors and, conversely, a given Actor may be played by multiple different instances." A librarian who borrows a book is acting as a member. UML draws an actor as a stick figure with its name near it: "An Actor is represented by a “stick man” icon with the name of the Actor in the vicinity (usually above or below) the icon".

Use cases are the things the system does for its actors, each drawn as an oval: "A UseCase is shown as an ellipse, either containing the name of the UseCase or with the name of the UseCase placed below the ellipse." Name each one with a verb and its object, from the actor's side: "Borrow Book", "Search Catalog", "Pay Fine". A noun such as "Book" or "Loan Handler" names a thing in the code, and a use case names something an actor wants done.

The system boundary is a rectangle around the use cases, with the system's name in its corner. UML calls the system the subject: "A subject for a set of UseCases (sometimes called a system boundary) may be shown as a rectangle with its name in the top-left corner, with the UseCase ellipses visually located inside this rectangle." Everything inside is part of the system you are designing, and the actors stand outside it. The boundary shows the scope at a glance: what the system does, and what it leaves to someone else.

Relationships join the elements. There are four kinds:

  • An association, a plain solid line, joins an actor to each use case it takes part in.
  • An «include» arrow, dashed, runs from a use case to another use case that always runs inside it.
  • An «extend» arrow, dashed, runs from a use case that adds behaviour under a condition to the use case it adds to.
  • A generalization, a solid line with a hollow triangle at the parent, says one actor is a kind of another. Librarian is a kind of Member: the arrow runs from Librarian to Member, and a librarian can do everything a member can, as in Generalization vs Specialization.

Notation Guide

The card shows each element and each line, on the library's own use cases:

A reference card for UML use case diagram notation, in four panels. 1, Elements: an actor, a stick figure standing for a person or an outside system, outside the system boundary; the boundary is a rectangle named System in its top-left corner, and inside it a use case, an oval, a thing the system does for an actor. 2, Association: the actor Member joined to the use case Search Catalog by a solid line, with multiplicity 1 at the Member end and any number at the use case end; a solid line joins an actor to each use case it takes part in, and multiplicity and a role name can sit at its ends. 3, Include and extend: Borrow Book has a dashed arrow marked «include» to Verify Membership, so borrowing always verifies membership; Apply Late Fee has a dashed arrow marked «extend» to Return Book, whose oval lists its extension point, late return, under the heading extension points, and a note on the arrow gives the condition, book overdue, so the late fee is added only when the book is overdue. 4, Generalization: Librarian has a solid line with a hollow triangle to Member; a hollow triangle means generalization, is-a, and Librarian inherits every Member use case and adds its own.

Include and Extend

«include» and «extend» are the two relationships between use cases, and they are easy to mix up because both are dashed arrows with a keyword. They differ in when the other use case runs, and in which way the arrow points.

«include»: it always runs

UML describes include in one sentence: "Include is a DirectedRelationship between two UseCases, indicating that the behavior of the included UseCase (the addition) is inserted into the behavior of the including UseCase (the includingCase)." Every time the base use case runs, the included one runs inside it. Borrow Book includes Verify Membership: no book is lent without checking that the member's account is valid. It works much like a function that always calls another function.

The arrow points from the base to the included use case, and UML gives the notation in so many words: "An Include relationship between UseCases is shown by a dashed arrow with an open arrowhead pointing from the base UseCase to the included UseCase. The arrow is labeled with the keyword «include»".

Include exists for behaviour that several use cases share: "The Include relationship is intended to be used when there are common parts of the behavior of two or more UseCases." Reserve Book checks the membership too, so in the library's diagram Verify Membership is included by both Borrow Book and Reserve Book, and written once. A base that includes something depends on it to make sense, since "what is left in a base UseCase is usually not complete in itself but dependent on the included parts to be meaningful."

«extend»: it runs only when its condition holds

An extension adds behaviour to a use case that is complete without it: "Extend is intended to be used when there is some additional behavior that should be added, possibly conditionally, to the behavior defined in one or more UseCases." The use case it extends stands on its own: "The extended UseCase is defined independently of the extending UseCase and is meaningful independently of the extending UseCase."

Apply Late Fee extends Return Book. A return on time is a whole return with no fee. The extension happens at a named place in the base, an extension point, here called late return, and only when the extension's condition is true there: "If the condition of the Extend is missing or evaluates to true at the time the first ExtensionPoint is reached during the execution of the extended UseCase, then all of the appropriate behavior fragments of the extending UseCase will also be executed. If the condition is false, this does not happen." The base can list its extension points inside its oval, under the heading extension points, and the condition can go in a note on the arrow.

The arrow points the other way from include, from the extension to the base it adds to: "An Extend relationship between UseCases is shown by a dashed arrow with an open arrowhead pointing from the extending UseCase towards the extended UseCase. The arrow is labeled with the keyword «extend»." So the arrow points at Return Book, though at run time the extra behaviour runs from inside Return Book. Either way it is a single run: "Note that even though there are multiple UseCases involved, there is just a single behavior execution."

Three ways to get them wrong

Drawing a step as «extend» when it always happens: if Return Book always updates the book's availability, that step is included, because it is not optional.

Turning an arrow round: «include» points from the base to the included use case, and «extend» points from the extension to the base. Read the include arrow as "Borrow Book includes Verify Membership" and the extend arrow as "Apply Late Fee extends Return Book", and the direction follows from the sentence.

Using include to split a use case into small steps. Include is for a part that several use cases share, at the level a user cares about; a chain of includes for each step of one use case turns the diagram into a flowchart, and that belongs in an activity diagram.

Run a Use Case

Run each of the member's use cases below. One dot is one run: it goes into every use case the base includes, and at Return Book's extension point it reads the condition before it goes into Apply Late Fee.

Run each of the member's use cases and watch one run travel through it: into every use case it includes, and into Apply Late Fee only when a return is late, entering from Return Book against the direction of the «extend» arrow.

Complete Example: The Library Use Case Diagram

Here is the whole use case diagram of the library's lending system:

The use case diagram of the Library Management System. Inside the system boundary are twelve use cases; three actors stand outside it. The Member, on the left, is joined to Search Catalog, Reserve Book, Borrow Book, Return Book and Pay Fine. Reserve Book and Borrow Book each include Verify Membership, and Borrow Book and Return Book each include Update Availability: dashed arrows marked «include» from each base use case to the one it includes. Apply Late Fee extends Return Book: a dashed arrow marked «extend» from Apply Late Fee to Return Book, with a note giving the condition, book overdue, and the extension point, late return. On the right, the Notification Service, an outside system, is joined to Send Overdue Notice, and the Librarian to Add Book, Register Member and Manage Fines. The Librarian is a Member: a solid line runs from the Librarian round under the boundary to the Member, ending in a hollow triangle, so a librarian can do every use case a member can. A key at the bottom shows association, «include» from the base to the included, «extend» from the extension to the base, and generalization from the child to the parent.

Read it actor by actor. The Member is joined to Search Catalog, Reserve Book, Borrow Book, Return Book and Pay Fine. The Librarian is joined to Add Book, Register Member and Manage Fines, and because a librarian is a member, the generalization arrow from Librarian to Member gives the librarian every member's use case as well. The Notification Service is an outside system: it takes part in Send Overdue Notice, which delivers the reminder when a book is past its due date.

The dashed arrows show what runs inside what. Verify Membership is included by Reserve Book and Borrow Book, and Update Availability by Borrow Book and Return Book, so each shared step is drawn once and reached from both. Apply Late Fee extends Return Book at the extension point late return, under the condition that the book is overdue, and the note on its arrow says both.

Send Overdue Notice has no arrow to Borrow Book or Return Book. An extension runs inside one run of its base, at an extension point, and a notice that goes out days after a loan is not part of any borrowing or return. It is a use case of its own.

How to Find Actors and Use Cases

Finding actors

Ask four questions about the system:

  1. Who uses it? These are the human actors, such as Member and Librarian.
  2. Which outside systems does it talk to? These are system actors, such as an email service or a payment gateway. The system's own database is part of the system and stays inside the boundary.
  3. Does anything happen at a set time? A timer or scheduler that starts it is an outside system too.
  4. Do different users have different rights? Each separate set of rights is usually a separate actor, and a generalization says when one actor can do everything another can.

Finding use cases

For each actor, ask what it does with the system (borrow a book, add a book), what it needs to learn from it (search the catalog, view its loans) and what it needs to be told (an overdue notice). Each answer is a candidate use case.

How big a use case should be

A use case is something an actor sits down to get done in one go, with a result they care about. "Borrow Book", "Return Book" and "Search Catalog" are each a whole goal. "Enter ISBN", "Press Submit" and "Validate Input" are steps of a screen, too small for this diagram. "Manage Library" is too broad, because no actor does it in one sitting; split it into the goals it is made of.

Common Mistakes in Use Case Diagrams

Mistake 1: an actor inside the boundary. A Member stick figure drawn inside the system's rectangle says the member is part of the system. Actors stand outside, because they use the system.

Mistake 2: use cases named like classes. Ovals labelled "Book", "Loan" or "Database" name things in the code. Use cases name what an actor wants done: "Borrow Book", "Return Book", "Search Catalog".

Mistake 3: a plain line between two use cases. UML does not allow one: "Two UseCases specifying the same subject cannot be associated as each of them individually describes a complete usage of the subject." Two use cases are linked by «include», «extend» or a generalization, and actors are linked to use cases by plain lines.

Mistake 4: include for every step. "Borrow Book" including "Open Book Record", "Check ISBN", "Update Counter" and "Generate Receipt" turns the diagram into a flowchart. Include a use case only when several use cases share it.

Mistake 5: data on the arrows. Arrows labelled with data, such as a book id or a member record, describe how data moves inside the system. A use case diagram shows what the system does and who uses it, and how the data moves is a job for sequence and activity diagrams.

Use Case Diagrams Before a Design

A use case sketch is a quick way to agree on scope before you design anything. Listing the actors makes you ask who uses the system, and the use cases list what each of them needs. Showing the sketch and asking whether anything is missing settles the scope early, when a change costs nothing; a reservation feature found after the classes are drawn costs a redesign. Step 1: Clarify Requirements & Define Scope covers this step of a design.

The sketch also feeds the next diagram. The actors and the nouns in the use case names (book, member, loan, fine) are the first candidates for classes, and the verbs in them (borrow, return, reserve) hint at methods. Class Diagrams — Structure of Your System shows where that leads for the library.

Sequence Diagrams — How Objects Interact Over Time takes one of these use cases, Borrow Book, and shows the messages its objects send each other while it runs.

Key Takeaways

  • A use case diagram shows who uses a system and what it does for them: actors as stick figures outside the boundary, use cases as ovals inside it.
  • An actor is a role, a person or another system; a use case is a goal an actor can reach in one go, named with a verb.
  • «include» always runs and points from the base to the included use case; «extend» runs only when its condition holds at an extension point, and points from the extension to the base.
  • Include is for a part several use cases share; a generalization between actors says one can do everything the other can.