UML作业第六次:分析系统,绘制顺序图

一、PlantUML顺序图 语法学习小结、图例及用法

1.简单示例:你可以用->来绘制参与者之间传递的消息, 而不必显式地声明参与者。你也可以使用 --> 绘制一个虚线箭头。另外,你还能用 <- 和 <--,这不影响绘图,但可以提高可读性。 注意:仅适用于时序图,对于其它示意图,规则是不同的。

1
2
3
4
5
6
7
@startuml
Alice -> DY: Authentication Request
DY --> Alice: Authentication Response
 
Alice -> DY: Another authentication Request
Alice <-- DY: another authentication Response
@enduml

 

2.声明参与者:关键字 participant 用于改变参与者的先后顺序。你也可以使用其它关键字来声明参与者:actor/ boundary/ control/ entity/ database

1
2
3
4
5
6
7
8
9
10
11
12
13
@startuml
actor Dingyi1
boundary Dingyi2
control Dingyi3
entity Dingyi4
database Dingyi5
collections Dingyi6
Dingyi1 -> Dingyi2 : To boundary
Dingyi1 -> Dingyi3 : To control
Dingyi1 -> Dingyi4 : To entity
Dingyi1 -> Dingyi5 : To database
Dingyi1 -> Dingyi6 : To collections
@enduml

 

3.在参与者中使用非字母符号:你可以使用引号定义参与者,还可以用关键字 as 给参与者定义别名。

1
2
3
4
5
6
7
@startuml
Alice -> "DY()" : Hello
"DY()" -> "This is very\nlong" as Long
' You can also declare:
' "DY()" -> Long as "This is very\nlong"
Long --> "DY()" : ok
@enduml

 

4.修改箭头样式:修改箭头样式的方式有以下几种:

  • 表示一条丢失的消息:末尾加 x
  • 让箭头只有上半部分或者下半部分:将<和>替换成\或者 /
  • 细箭头:将箭头标记写两次 (如 >> 或 //)
  • 虚线箭头:用 -- 替代 -
  • 箭头末尾加圈:->o
  • 双向箭头:<->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@startuml
DY ->x Alice
DY -> Alice
DY ->> Alice
DY -\ Alice
DY \\- Alice
DY //-- Alice
 
DY ->o Alice
DY o\\-- Alice
 
DY <-> Alice
DY <->o Alice
@enduml

 

5.对消息序列编号:关键字 autonumber 用于自动对消息编号。语句 autonumber start 用于指定编号的初始值,而 autonumber startincrement 可以同时指定编号的初始值和每次增加的值。

1
2
3
4
5
6
7
8
9
10
11
12
13
@startuml
autonumber
DY -> Alice : Authentication Request
DY <- Alice : Authentication Response
 
autonumber 15
DY -> Alice : Another authentication Request
DY <- Alice : Another authentication Response
 
autonumber 40 10
DY -> Alice : Yet another authentication Request
DY <- Alice : Yet another authentication Response
@enduml

 

6.组合消息:我们可以通过以下关键词将组合消息:

  • alt/else
  • opt
  • loop
  • par
  • break
  • critical
  • group

后面紧跟着消息内容可以在标头(header)添加需要显示的文字(group除外)。关键词 end 用来结束分组。注意,分组可以嵌套使用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@startuml
Alice -> DY: Authentication Request
 
alt successful case
 
    DY -> Alice: Authentication Accepted
     
else some kind of failure
 
    DY -> Alice: Authentication Failure
    group My own label
        Alice -> Log : Log attack start
        loop 1000 times
            Alice -> DY: DNS Attack
        end
        Alice -> Log : Log attack end
    end
     
else Another type of failure
 
   DY -> Alice: Please repeat
    
end
@enduml

 

7.给消息添加注释:我们可以通过在消息后面添加 note left 或者 note right 关键词来给消息添加注释。你也可以通过使用 end note 来添加多行注释。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@startuml
Alice->DY : hello
note left: this is a first note
 
DY->Alice : ok
note right: this is another note
 
DY->DY : I am thinking
note left
    a note
    can also be defined
    on several lines
end note
@enduml

 

 

二、语言描述《工厂采购》系统对象交互顺序

  采购员选择采购货品,到订货界面,接收客户信息,接收货品信息,显示货品信息,到订货管理器,创建客户,取货品信息,创建订单,创建客户到客户区,取货品信息到货品区,创建订单到订单区。

 

三、用PlantUML的绘制《工厂采购》系统的对象交互的脚本程序、绘制的顺序图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@startuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam maxmessagesize 60
skinparam sequenceParticipant underline
 
actor 采购员
participant "订货界面" as A
participant "订货管理器" as B
participant "客户" as C
participant "货品" as D
participant "订单" as E
 
采购员 -> A: 客户信息()
activate A
采购员 -> A: 选择订货货品()
activate A
 
A -> B:接收客户信息()
activate B
A -> B:接收货品信息()
activate B
B --> A: 显示货品信息()
deactivate B
 
B -> C: 创建客户()<<create>>
activate C
B -> D: 取货品信息()
activate D
D --> B: 货品信息()
activate D
B -> E: 创建订单()<<create>>
activate E
@enduml

 

posted @ 2019-05-31 21:15  杨州  阅读(228)  评论(0编辑  收藏  举报