UML Use Case Diagram

A use case is a specification for some behavior. It’s usually a specification so that some entity – an actor – can achieve some goal, like making a purchase or updating payment information. An actor can be a person or some other system or entity that interacts with the use case.

The UML-Diagrams.org site has some good explanations and examples of use case diagrams and the notations for and components of them.

You can read more about formal UML Use case definitions and diagrams in the UML Specification section 18: “Use Cases.”

Keywords

Arrows (Graphic Paths)

Graphic paths in Use Case diagrams use arrows to show relationships between use cases and actors.

Here is a Use Case diagram showing the different arrow head styles and arrow colors:

@startuml
'!include ../../plantuml-styles/plantuml-ae.iuml

skinparam Shadowing false

skinparam ArrowFontStyle normal
skinparam ArrowFontName Courier
skinparam ArrowFontSize 10

title Arrows in Use Case diagrams\n


(Manage Users) -up-|> (Management): This arrow is -up-|>

:All Users:      as allUsers #violet
:Main Admin:     as Admin    #saddleBrown
:User:           as U        #tan
:System Manager: as manager

Admin   -up-|>    allUsers: This arrow is -up->
manager -right-|> allUsers: This arrow is -right-|>
U       -|>       allUsers: This arrow is -|>

Admin --> U:    This arrow is -->
Admin <.....> U: This arrow is <.....>

Admin   -[#blue]->    (Manage Users): This arrow is -[#blue]->
manager -[#blue]->> (Manage Users): This arrow is -[#blue]->>


'!include ../../plantuml-styles/ae-copyright-footer.txt
@enduml

Here is the code for the above diagram:

@startuml
'!include ../../plantuml-styles/plantuml-ae.iuml

skinparam Shadowing false

skinparam ArrowFontStyle normal
skinparam ArrowFontName Courier
skinparam ArrowFontSize 10

title Arrows in Use Case diagrams\n


(Manage Users) -up-|> (Management): This arrow is -up-|>

:All Users:      as allUsers #violet
:Main Admin:     as Admin    #saddleBrown
:User:           as U        #tan
:System Manager: as manager

Admin   -up-|>    allUsers: This arrow is -up->
manager -right-|> allUsers: This arrow is -right-|>
U       -|>       allUsers: This arrow is -|>

Admin --> U:    This arrow is -->
Admin <.....> U: This arrow is <.....>

Admin   -[#blue]->    (Manage Users): This arrow is -[#blue]->
manager -[#blue]->> (Manage Users): This arrow is -[#blue]->>


'!include ../../plantuml-styles/ae-copyright-footer.txt
@enduml

Arrow Heads

Arrow Lines

  • Can make them long so that they are drawn longer.

Ex:

Todo

show arrow lines of different lengths. (dashed, dotted); with directions within

Arrow Color

You can change the color of an arrow by putting the color within square brackets just before the ending arrow-head characters:

Ex: -[#magenta]>> will create a magenta colored unfilled arrow with a solid line

Ex: --[#939393]> will create a gray colored filled arrow with a dashed line

  • cannot have both color and direction in an arrow line

Arrow Direction

  • left, right, up, down
  • does it always work???
  • cannot have both color and direction in an arrow line

Notes

You can use the note left of , note right of , note top of , note bottom of keywords to define notes related to a single object.

A note can be also define alone with the note keywords, then linked to other objects using the .. symbol.

Usage for a note positioned relative to an object:
 

note  <direction> of <actor | use case> [#<color name | hex code>] :  <note text>

or written with many lines:

note  <direction> of <actor | use case> [#<color name | hex code>]
  <note text on 1 or more separate lines>
end note
Usage for a note given an alias:
 

note "<note text>" [as <alias>] [#<color name | hex code>]

or written with many lines:

note  <direction> of <actor | use case> [#<color name | hex code>]
<note text on 1 or more separate lines>
end note

Note

You can create a note that is positioned relative to an object or a note that has an alias. You can’t create a note that is both positioned and has an alias.

@startuml

'!include ../../plantuml-styles/plantuml-ae.iuml

skinparam ActorBorderColor   SaddleBrown
skinparam NoteFontStyle normal
skinparam Shadowing false
skinparam ActorFontSize 13

title Usecase Diagrams: Notes

:Admin: #saddleBrown

(Use the application) as (Use)

User -> (Start)
User --> (Use)
Admin ---> (Use)

note right of Admin #lightBlue : <i>The code for this note starts:\nnote right of Admin #lightBlue :

note right of (Use) #Azure
A note can also
be on several lines.
<i>The code for this note starts:
note right of (Use the application) ...
end note

note "This note has an alias so \nit can be connected.\nIt is connected to the 'Start' and\n 'Use the application' usecases. \n\n<i>The code for this note ends with\n      ... as N2"  as N2

(Start) .. N2
N2 .. (Use)

note  as freeFloatingNote #white
 This is a multi-lined note with an alias
 but it's not connected to anything.
 It is automatically positioned.
end note


'!include ../../plantuml-styles/ae-copyright-footer.txt
@enduml

Connecting Notes to Objects

To connect a note to an object, the note must have an alias. You use an arrow to connect a note (using the alias for it) to an object. Any valid arrow can be used.

Here is a very ugly example that uses differen kinds of arrows to connect a note. (It’s shortened from the above diagram)

@startuml
'!include ../../plantuml-styles/plantuml-ae.iuml

skinparam ActorBorderColor   SaddleBrown
skinparam NoteFontStyle normal
skinparam Shadowing false


title Usecase Diagrams: Connecting Notes to Objects

(Use the application) as (Use)

User -[#LightSlateGray]-> (Start)
User -[#LightSlateGray]-> (Use)

note "This note is connected to \n two use cases \n and the User actor."  as N2  #white

(Start) <<-[#orange]- N2
N2 .[#magenta].|> (Use)
User <==[#DeepSkyBlue]==> N2

'!include ../../plantuml-styles/ae-copyright-footer.txt
@enduml

and here is the code for that diagram:

@startuml
'!include ../../plantuml-styles/plantuml-ae.iuml

skinparam ActorBorderColor   SaddleBrown
skinparam NoteFontStyle normal
skinparam Shadowing false


title Usecase Diagrams: Connecting Notes to Objects

(Use the application) as (Use)

User -[#LightSlateGray]-> (Start)
User -[#LightSlateGray]-> (Use)

note "This note is connected to \n two use cases \n and the User actor."  as N2  #white

(Start) <<-[#orange]- N2
N2 .[#magenta].|> (Use)
User <==[#DeepSkyBlue]==> N2

'!include ../../plantuml-styles/ae-copyright-footer.txt
@enduml

Skinparams specific to Use Case Diagrams

UsecaseBackgroundColor
UsecaseBorderColor
UsecaseBorderThickness

UsecaseFontColor
UsecaseFontName
UsecaseFontSize
UsecaseFontStyle

UsecaseStereotypeFontColor
UsecaseStereotypeFontName
UsecaseStereotypeFontSize
UsecaseStereotypeFontStyle