UML Use Case Diagram
To create a UML use case diagram, use the useCaseDiagram function:
useCaseDiagram {
// define elements
}A use case diagram says who uses a system and what they use it for, and it is built from very few elements: the actors outside the system, the use cases inside it, the subject that separates the two, and the associations that cross the boundary. All elements described below are also available in the general UML diagram.
Elements
useCase
Creates a use case, rendered as an ellipse with its name inside:
The ellipse is grown around its name rather than the name being squeezed into a fixed oval, so a long name widens the use case instead of overflowing it.
Extension points
A use case that is extended by another one names the points at which that may happen. They are declared with extensionPoints, and are rendered in a compartment of their own below the name, under the heading UML prescribes for it. As with enum entries, the block is not executed but read on the AST level, so the points may be written as identifiers or as strings:
Further compartments
A use case is a classifier, so section adds a plain compartment, which is where a precondition or a postcondition is usually written:
actor
Creates an actor, rendered as a stick man. This is the same element the sequence diagram uses:
systemActor
Creates an actor in the rectangle notation, the alternative UML offers for the stick man. It is a classifier carrying the «actor» keyword, and is conventionally used for the actors which are not people - external systems, clocks, sensors - so that a reader can tell at a glance which of the actors is human:
Both notations mean the same thing, and both are associated with a use case in exactly the same way.
subject
Creates the subject, the system boundary: a rectangle with its name at the top, holding the use cases that apply to it.
Drawing a use case inside the subject is the whole of the statement that it belongs to that system, so nothing else has to be written down for it. Actors belong outside, and only the association crosses the boundary - which it may, as the use cases inside a subject are registered in the diagram scope just like every other element:
Further elements
instance, package and comment are available as well, and behave exactly as in the class diagram.
Connections
A use case diagram draws its connections as straight lines rather than as the axis-aligned routes the other diagram types use, so this is the one diagram type where defaultLineType defaults to line, see config properties. A connection therefore needs no over at all unless it should leave its elements somewhere other than the default, which is the right side of the start and the left side of the end.
Association
The line between an actor and a use case is a plain association, so the -- operator already is one. Multiplicities are written on it as ordinary labels:
«include» and «extend»
Both are dependencies, and are distinguished from any other dependency only by their keyword. They are therefore written with the dashed arrow ..> and an «include» respectively «extend» label, the same way the deployment diagram writes its stereotyped dependencies.
The two point in opposite directions, which is the part worth getting right: an «include» points from the base use case to the one it always includes, an «extend» from the extending use case back to the base one it may extend.
The condition of an «extend» and the extension point it applies to are written in a comment attached to the connection.
Generalization
An actor may specialize another actor, and a use case another use case. Both are the ordinary generalization, so the extends operator is used for them:
Further connections
For additional connection types, refer to the class diagram documentation.
Config properties
The following config properties are available for use case diagrams:
| Variable | Meaning | Default value | Comment |
|---|---|---|---|
abstractAsProperty | Whether to show { abstract } after the name of abstract classifiers | false | - |
defaultLineType | How a connection without an explicit over is routed | "line" | "axisAligned" in every other diagram type, see connections |
Example
The following example shows a small shop, using all of the elements described above: