Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 39 ยท Use Case and Activity Diagrams

Use Case Relationships: Include, Extend, Generalization

Understand the three relationships between use cases and the generalization between actors: when to use include, extend and generalization, with examples and pitfalls.

Real systems have use cases that share behavior, optional behavior and variations of one goal. UML gives three relationships to structure them: include, extend and generalization. They are often confused, even by experienced modelers, so this lesson gives each a one-line test and plenty of examples.

Include: always part of the base

Include means the base use case always performs the included use case as one of its steps. The included use case is extracted because several others share it, or to simplify a big description. The dashed arrow points from the base to the included use case and carries <<include>>.

flowchart LR
    Customer(["Customer"])
    subgraph Shop["Online Shop"]
        Order(("Place Order"))
        Pay(("Pay"))
        Auth(("Authenticate"))
        Refund(("Request Refund"))
    end
    Customer --- Order
    Customer --- Refund
    Order -. "include" .-> Pay
    Order -. "include" .-> Auth
    Refund -. "include" .-> Auth

Both Place Order and Request Refund always include Authenticate. Without it, they cannot complete.

Test: "Does the base ever finish without this?" If the answer is no, use include. Include is the use case analog of calling a shared subroutine. The base depends on the included case, not the other way round.

Extend: optional, conditional additions

Extend adds behavior to a base use case only under a condition, at a named point. The dashed arrow points from the extending use case to the base, labelled <<extend>>. The base does not know about its extensions; it is complete without them.

flowchart LR
    Customer(["Customer"])
    subgraph Shop["Online Shop"]
        Order(("Place Order"))
        Coupon(("Apply Coupon"))
        Gift(("Add Gift Wrap"))
    end
    Customer --- Order
    Coupon -. "extend" .-> Order
    Gift -. "extend" .-> Order

Place Order works alone. Apply Coupon and Add Gift Wrap kick in only when the customer chooses them.

An extend relationship has a condition and an extension point (where in the base flow it applies), both usually written in a note: condition: customer has a coupon code, extension point: before payment.

Test: "Is this optional, rare, or only under a condition?" If yes, use extend. Extending keeps the base flow simple and puts exceptional or special behavior in its own place.

Include versus extend

Include Extend
Is it always executed? Yes Only if the condition holds
Who depends on whom? Base depends on included Extension depends on base
Arrow points to the included use case the base use case
Stereotype <<include>> <<extend>>
Typical reason reuse or decomposition optional or special behavior
Base complete without it? No Yes

A memory trick: the include arrow points to the part that is used; the extend arrow points to the thing being extended. The arrow always shows "depends on".

Generalization of use cases

One use case can be a specialized variant of another. The child inherits the parent's goal and steps and may refine them. The line is a solid line with a hollow triangle pointing at the parent.

flowchart LR
    Customer(["Customer"])
    subgraph Shop["Online Shop"]
        Pay(("Pay for Order"))
        Card(("Pay by Card"))
        Voucher(("Pay by Voucher"))
    end
    Customer --- Pay
    Card -- "is a" --> Pay
    Voucher -- "is a" --> Pay

Pay by Card and Pay by Voucher are two ways of Pay for Order.

Use generalization when several use cases are the same goal reached in different ways, and you want the common goal visible. Do not overuse it: many teams capture variations as alternative flows inside the written use case instead.

Generalization of actors

Actors can also inherit. A Premium Customer can do everything a Customer can, plus more. The child actor is linked to the parent with a hollow triangle, and only the extra use cases are attached to the child.

flowchart LR
    Customer(["Customer"])
    Premium(["Premium Customer"])
    subgraph Shop["Online Shop"]
        Order(("Place Order"))
        Express(("Use Express Shipping"))
    end
    Premium -- "is a" --> Customer
    Customer --- Order
    Premium --- Express

Premium customers inherit Place Order and additionally use express shipping.

Deciding which relationship to use

Which relationship?

Include Always happens. Shared step.
Extend Sometimes happens. Optional.
Generalize Same goal, different way.

Ask: always, sometimes, or a variant?

1 / 2
Python Model relationships and compute what a use case needs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Choose the relationship from two yes/no answers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The third example shows a real trap: not every step deserves its own use case. If a step is always done and used nowhere else, leave it as a step in the written description.

Common mistakes

  • Reversing the arrows. Include points at the included use case; extend points at the base.
  • Using include for optional behavior (or extend for mandatory behavior).
  • Functional decomposition. Splitting a use case into many tiny includes turns the diagram into a flow chart. Include only for reuse or real complexity.
  • Too many extends. If the base cannot be understood without its extensions, it is incomplete; rethink the split.
  • Relationships between actors and use cases other than association (apart from actor generalization).

Many teams avoid include and extend at first. They write complete use case text and add these relationships later, only where they remove real duplication.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Authenticate is needed by several use cases and always runs as part of them. Which relationship?

    Mandatory, shared behavior is extracted with include.
  2. 2. Which arrow direction is correct for extend?

    The extending use case depends on the base, so the arrow points at the base.
  3. 3. Apply Coupon happens only if the customer enters a code. This is:

    Conditional, optional behavior is an extension.
  4. 4. What does generalization between two use cases mean?

    Child use cases specialize a shared goal, like different payment methods.
  5. 5. Premium Customer inherits from Customer. What does the Premium actor get?

    Actor generalization passes on the parent's associations to the child.

Summary

  • <<include>>: always executed, arrow points to the included use case; for reuse.
  • <<extend>>: optional and conditional, arrow points to the base; the base stays complete.
  • Generalization models variants of one goal, for use cases and for actors.
  • Test with questions: always? sometimes? a variant?
  • Do not split use cases into tiny pieces just to use the notation.

Next: Use Case Specifications