目录
用例图主要内容
用例图是我们平时工作中最常用的一种图,它能够直观的体现业务的参与者和用例,一个简单的用例图包含用例和角色两个部分,下面就是一张简单的用例图
@startuml
(Use the application) as app
:User: -> (start)
:User: --> app : A small lable:Main Admin: ---> app : This is\nyet another\nlabel
@enduml
用例
我们有两种方式来表示一个用例
- 一种是使用关键字 usecase 来定义用例,
- 另外一种则直接使用圆括号括起来即可。
这两种的后面都可以使用 as 作为别名。
@startuml
(First case)
usecase "Second case"
(Another case) as another@enduml
如果你想定义跨越多行的用例描述,可以用双引号将其裹起来,并且可以使用这些分隔符:--..==__
@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
角色
和用例一样,角色也有两种方式来表示。
- 一种是使用关键字 actor 来定义
- 另一种是使用两个冒号包裹起来。
@startuml
actor userA
:UserB:
:UserC: as userC@enduml
继承
我们可以把用例和角色看成两个对象,是对象就有继承,我们可以用 <|-- 符号表示。
@startuml
actor factor as f
actor son as s
(Main Case) as main
(Sub Case) as subf <|-- s
main <|-- sub@enduml
使用注释
可以用note left of , note right of , note top of , note bottom of等关键字给一个对象添加注释。注释还可以通过note关键字来定义,然后用..连接其他对象。
@startuml
:Main Admin: as Admin
(Use the application) as (Use)User -> (Start)
User --> (Use)Admin ---> (Use)
note right of Admin : This is an example.
note right of (Use)
A note can also
be on several lines
end notenote "This note is connected\nto several objects." as N2
(Start) .. N2
N2 .. (Use)
@enduml
构造类型
用 << 和 >> 来定义角色或者用例的构造类型。
@startuml
:User: << Human >>
:Main Database: << Application >> as db
(Start) << One Shot >>
(Use the application) << Main >> as app:User: -> (Start)
:User: --> app
db --> app
@enduml
改版箭头方向
默认连接是竖直方向的,用 -- 表示,可以用一个横杠或点来表示水平连接。如果想用虚线,可以把 - 换成 .
如果要改变方便,只需要改变箭头 > 为 < 并放到 - 的左边。
@startuml
:User: -> (Earth)
:User: --> (South)
(West) <. :User:
(North) <.. :User:@enduml
案例
同样的,我们用一个例子来巩固一下学习的知识:
@startuml
left to right direction
actor bkautoapprove << System >>
usecase 采集服务 << Service >>
usecase 采集请求服务 << Service >>
usecase 采集节点服务 << Service >>usecase (是否需要采集) << method >>
usecase (采集是否授权) << method >>
usecase (采集) << method >>
usecase (是否全部采集完成) << method >>
usecase (完成采集) << method >>
usecase (采集中断) << method >>
usecase (查询采集请求) << method >>
usecase (更新采集请求) << method >>
usecase (节点是否初始化完成) << method >>
usecase (初始化节点) << method >>
usecase (获取下一批节点) << method >>
usecase (获取下一个节点) << method >>
usecase (更新节点状态) << method >>bkautoapprove ..> 采集请求服务
bkautoapprove ..> 采集服务
bkautoapprove ..> 采集节点服务采集服务 --> (是否需要采集) : include
采集服务 ---> (采集是否授权) : include
采集服务 --> (采集) : include
采集服务 ---> (是否全部采集完成) : include
采集服务 --> (完成采集) : include
采集服务 ---> (采集中断) : include采集请求服务 --> (查询采集请求) : include
采集请求服务 --> (更新采集请求) : include采集节点服务 --> (节点是否初始化完成) : include
采集节点服务 --> (初始化节点) : include
采集节点服务 --> (获取下一批节点) : include
采集节点服务 --> (获取下一个节点) : include
采集节点服务 --> (更新节点状态) : includenote bottom of 采集服务 : 对应于lncian_collect_req表
note top of 采集节点服务 : 对应于lncian_collect_node表
@enduml