@startuml left to right direction skinparam packageStyle rectangle actor customer actor clerk rectangle checkout { customer -- (checkout) (checkout) .> (payment) : include (help) .> (checkout) : extends (checkout) -- clerk } @enduml
1 定义
用例
用例用圆括号括起来(两个圆括号看起来就像椭圆)。
也可以用关键字usecase来定义用例。
角色
角色用两个冒号包裹起来。 也可以用actor关键字来定义角色。
1 2 3 4 5 6 7 8 9 10 11
@startuml
(First usecase) (Another usecase) as (UC2) usecase UC3 usecase (Last\nusecase) as UC4 :First Actor: :Another\nactor: as Man2 actor Woman3 actor :Last actor: as Person1 @enduml
2 角色样式
火柴人样式:默认
用户头像样式:skinparam actorStyle awesome
透明人样式:skinparam actorStyle hollow
3 用例描述
–(横线)
..(虚线)
==(双横线)
__(下划线)
1 2 3 4 5 6 7 8 9 10 11 12 13
@startuml
usecase UC1 as "You can use several lines to define your usecase. You can also use separators. -- Several separators are possible. == And you can add titles: ..Conclusion.. This allows large description."
@enduml
4 用例包
package 可以一使用包来对角色或用例进行分组。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
@startuml left to right direction actor Guest as g package Professional { actor Chef as c actor "Food Critic" as fc } package Restaurant { usecase "Eat Food" as UC1 usecase "Pay for Food" as UC2 usecase "Drink" as UC3 usecase "Review" as UC4 } fc --> UC4 g --> UC1 g --> UC2 g --> UC3 @enduml
5 继承关系
如果一个角色或者用例继承于另一个,那么可以用<|–符号表示。
1 2 3 4 5 6 7 8
@startuml :Main Admin: as Admin (Use the application) as (Use)
User <|-- Admin (Start) <|-- (Use)
@enduml
6 使用注释
可以用note left of , note right of , note top of , note bottom of等关键字给一个对象添加注释。
@startuml actor foo foo --> (bar) : normal foo --> (bar1) #line:red;line.bold;text:red : red bold foo --> (bar2) #green;line.dashed;text:green : green dashed foo --> (bar3) #blue;line.dotted;text:blue : blue dotted @enduml
改变用例风格
1 2 3 4 5 6
@startuml actor a actor b #pink;line:red;line.bold;text:red usecase c #palegreen;line:green;line.dashed;text:green usecase d #aliceblue;line:blue;line.dotted;text:blue @enduml