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

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

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

@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

@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 给参与者定义别名。

@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
  • 双向箭头:<->
@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 可以同时指定编号的初始值和每次增加的值。

@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 用来结束分组。注意,分组可以嵌套使用。

@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 来添加多行注释。

@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的绘制《工厂采购》系统的对象交互的脚本程序、绘制的顺序图

@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

 

 

转载于:https://www.cnblogs.com/dingyitrigger/p/10838633.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值