1. 程式人生 > >分析工廠采購系統,畫出順序圖

分析工廠采購系統,畫出順序圖

action spl 多行標題 else src ext this tex fail

第一部分:順序圖語法

(1)簡單示例:你可以用->來繪制參與者之間傳遞的消息, 而不必顯式地聲明參與者。你也可以使用 --> 繪制一個虛線箭頭。另外,你還能用 <-<--,這不影響繪圖,但可以提高可讀性。 註意:僅適用於時序圖,對於其它示意圖,規則是不同的。

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

技術分享圖片

(2)聲明參與者:關鍵字 participant 用於改變參與者的先後順序。

你也可以使用其它關鍵字來聲明參與者:

  • actor
  • boundary
  • control
  • entity
  • database
 1 @startuml
 2 actor Foo1
 3 boundary Foo2
 4 control Foo3
 5 entity Foo4
 6 database Foo5
 7 collections Foo6
 8
Foo1 -> Foo2 : To boundary 9 Foo1 -> Foo3 : To control 10 Foo1 -> Foo4 : To entity 11 Foo1 -> Foo5 : To database 12 Foo1 -> Foo6 : To collections 13 14 @enduml
 1 @startuml
 2 actor Bob #red
 3 ‘ The only difference between actor
 4 ‘and participant is the drawing
 5 participant Alice
6 participant "I have a really\nlong name" as L #99FF99 7 /‘ You can also declare: 8 participant L as "I have a really\nlong name" #99FF99 9 ‘/ 10 11 Alice->Bob: Authentication Request 12 Bob->Alice: Authentication Response 13 Bob->L: Log transaction 14 @enduml

技術分享圖片技術分享圖片

您可以使用關鍵字 order自定義順序來打印參與者。

1 @startuml
2 participant Last order 30
3 participant Middle order 20
4 participant First order 10
5 @enduml

技術分享圖片

(3)在參與者中使用非字母符號:你可以使用引號定義參與者,還可以用關鍵字 as 給參與者定義別名。

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

技術分享圖片

(4)給自己發消息:參與者可以給自己發信息,消息文字可以用\n來換行。

1 @startuml
2 Alice->Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
3 @enduml

技術分享圖片

(5)修改箭頭樣式:修改箭頭樣式的方式有以下幾種:

  • 表示一條丟失的消息:末尾加 x
  • 讓箭頭只有上半部分或者下半部分:將<>替換成\或者 /
  • 細箭頭:將箭頭標記寫兩次 (如 >>//)
  • 虛線箭頭:用 -- 替代 -
  • 箭頭末尾加圈:->o
  • 雙向箭頭:<->
 1 @startuml
 2 Bob ->x Alice
 3 Bob -> Alice
 4 Bob ->> Alice
 5 Bob -\ Alice
 6 Bob \\- Alice
 7 Bob //-- Alice
 8 
 9 Bob ->o Alice
10 Bob o\\-- Alice
11 
12 Bob <-> Alice
13 Bob <->o Alice
14 @enduml

技術分享圖片

(6)對消息序列編號:關鍵字 autonumber 用於自動對消息編號。語句 autonumber start 用於指定編號的初始值,而 autonumber startincrement 可以同時指定編號的初始值和每次增加的值。

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

技術分享圖片技術分享圖片

 1 @startuml
 2 autonumber "<b>[000]"
 3 Bob -> Alice : Authentication Request
 4 Bob <- Alice : Authentication Response
 5 
 6 autonumber 15 "<b>(<u>##</u>)"
 7 Bob -> Alice : Another authentication Request
 8 Bob <- Alice : Another authentication Response
 9 
10 autonumber 40 10 "<font color=red><b>Message 0  "
11 Bob -> Alice : Yet another authentication Request
12 Bob <- Alice : Yet another authentication Response
13 
14 @enduml
 1 @startuml
 2 autonumber 10 10 "<b>[000]"
 3 Bob -> Alice : Authentication Request
 4 Bob <- Alice : Authentication Response
 5 
 6 autonumber stop
 7 Bob -> Alice : dummy
 8 
 9 autonumber resume "<font color=red><b>Message 0  "
10 Bob -> Alice : Yet another authentication Request
11 Bob <- Alice : Yet another authentication Response
12 
13 autonumber stop
14 Bob -> Alice : dummy
15 
16 autonumber resume 1 "<font color=blue><b>Message 0  "
17 Bob -> Alice : Yet another authentication Request
18 Bob <- Alice : Yet another authentication Response
19 @enduml

技術分享圖片技術分享圖片

(7)組合消息:我們可以通過以下關鍵詞將組合消息:

  • alt/else
  • opt
  • loop
  • par
  • break
  • critical
  • group, 後面緊跟著消息內容

可以在標頭(header)添加需要顯示的文字(group除外)。關鍵詞 end 用來結束分組。註意,分組可以嵌套使用。

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

技術分享圖片

(8)給消息添加註釋:我們可以通過在消息後面添加 note left 或者 note right 關鍵詞來給消息添加註釋。你也可以通過使用 end note 來添加多行註釋。

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

技術分享圖片

(9)Creole和HTML:

 1 @startuml
 2 participant Alice
 3 participant "The **Famous** Bob" as Bob
 4 
 5 Alice -> Bob : hello --there--
 6 ... Some ~~long delay~~ ...
 7 Bob -> Alice : ok
 8 note left
 9   This is **bold**
10   This is //italics//
11   This is ""monospaced""
12   This is --stroked--
13   This is __underlined__
14   This is ~~waved~~
15 end note
16 
17 Alice -> Bob : A //well formatted// message
18 note right of Alice 
19  This is <back:cadetblue><size:18>displayed</size></back> 
20  __left of__ Alice. 
21 end note
22 note left of Bob 
23  <u:red>This</u> is <color #118888>displayed</color> 
24  **<color purple>left of</color> <s:red>Alice</strike> Bob**. 
25 end note
26 note over Alice, Bob
27  <w:#FF33FF>This is hosted</w> by <img sourceforge.jpg>
28 end note 
29 @enduml

技術分享圖片

(10)分隔符:你可以通過使用 == 關鍵詞來將你的圖表分割多個步驟。

 1 @startuml
 2 
 3 == Initialization ==
 4 
 5 Alice -> Bob: Authentication Request
 6 Bob --> Alice: Authentication Response
 7 
 8 == Repetition ==
 9 
10 Alice -> Bob: Another authentication Request
11 Alice <-- Bob: another authentication Response
12 
13 @enduml

技術分享圖片

(11)生命線的激活與撤銷:關鍵字activatedeactivate用來表示參與者的生命活動。一旦參與者被激活,它的生命線就會顯示出來。activatedeactivate適用於以上情形。destroy表示一個參與者的生命線的終結。

 1 @startuml
 2 participant User
 3 
 4 User -> A: DoWork
 5 activate A
 6 
 7 A -> B: << createRequest >>
 8 activate B
 9 
10 B -> C: DoWork
11 activate C
12 C --> B: WorkDone
13 destroy C
14 
15 B --> A: RequestCreated
16 deactivate B
17 
18 A -> User: Done
19 deactivate A
20 
21 @enduml
 1 @startuml
 2 participant User
 3 
 4 User -> A: DoWork
 5 activate A #FFBBBB
 6 
 7 A -> A: Internal call
 8 activate A #DarkSalmon
 9 
10 A -> B: << createRequest >>
11 activate B
12 
13 B --> A: RequestCreated
14 deactivate B
15 deactivate A
16 A -> User: Done
17 deactivate A
18 
19 @enduml

技術分享圖片技術分享圖片

(12)進入和發出消息:如果只想關註部分圖示,你可以使用進入和發出箭頭。使用方括號[]表示圖示的左、右兩側。

 1 @startuml
 2 [-> A: DoWork
 3 
 4 activate A
 5 
 6 A -> A: Internal call
 7 activate A
 8 
 9 A ->] : << createRequest >>
10 
11 A<--] : RequestCreated
12 deactivate A
13 [<- A: Done
14 deactivate A
15 @enduml
 1 @startuml
 2 [-> Bob
 3 [o-> Bob
 4 [o->o Bob
 5 [x-> Bob
 6 
 7 [<- Bob
 8 [x<- Bob
 9 
10 Bob ->]
11 Bob ->o]
12 Bob o->o]
13 Bob ->x]
14 
15 Bob <-]
16 Bob x<-]
17 @enduml

技術分享圖片技術分享圖片

(13)構造類型和圈點:可以使用<<>>給參與者添加構造類型。在構造類型中,你可以使用(X,color)格式的語法添加一個圓圈圈起來的字符。

1 @startuml
2 
3 participant "Famous Bob" as Bob << Generated >>
4 participant Alice << (C,#ADD1B2) Testable >>
5 
6 Bob->Alice: First message
7 
8 @enduml
1 @startuml
2 
3 skinparam guillemet false
4 participant "Famous Bob" as Bob << Generated >>
5 participant Alice << (C,#ADD1B2) Testable >>
6 
7 Bob->Alice: First message
8 
9 @enduml

技術分享圖片技術分享圖片

(14)更多標題信息:在標題描述中使用\n表示換行。還可以使用關鍵字titleend title定義多行標題。

1 @startuml
2 
3 title __Simple__ communication example\non several lines
4 
5 Alice -> Bob: Authentication Request
6 Bob -> Alice: Authentication Response
7 
8 @enduml
 1 @startuml
 2 
 3 title
 4  <u>Simple</u> communication example
 5  on <i>several</i> lines and using <font color=red>html</font>
 6  This is hosted by <img:sourceforge.jpg>
 7 end title
 8 
 9 Alice -> Bob: Authentication Request
10 Bob -> Alice: Authentication Response
11 
12 @enduml

技術分享圖片技術分享圖片

(15)包裹參與者:可以使用boxend box畫一個盒子將參與者包裹起來。還可以在box關鍵字之後添加標題或者背景顏色。

 1 @startuml
 2 
 3 box "Internal Service" #LightBlue
 4     participant Bob
 5     participant Alice
 6 end box
 7 participant Other
 8 
 9 Bob -> Alice : hello
10 Alice -> Other : hello
11 
12 @enduml

技術分享圖片

(16)移除腳註:使用hide footbox關鍵字移除腳註。

1 @startuml
2 
3 hide footbox
4 title Footer removed
5 
6 Alice -> Bob: Authentication Request
7 Bob --> Alice: Authentication Response
8 
9 @enduml

技術分享圖片

(17)外觀參數(skinparam):

 1 @startuml
 2 skinparam sequenceArrowThickness 2
 3 skinparam roundcorner 20
 4 skinparam maxmessagesize 60
 5 skinparam sequenceParticipant underline
 6 
 7 actor User
 8 participant "First Class" as A
 9 participant "Second Class" as B
10 participant "Last Class" as C
11 
12 User -> A: DoWork
13 activate A
14 
15 A -> B: Create Request
16 activate B
17 
18 B -> C: DoWork
19 activate C
20 C --> B: WorkDone
21 destroy C
22 
23 B --> A: Request Created
24 deactivate B
25 
26 A --> User: Done
27 deactivate A
28 
29 @enduml
 1 @startuml
 2 skinparam backgroundColor #EEEBDC
 3 skinparam handwritten true
 4 
 5 skinparam sequence {
 6     ArrowColor DeepSkyBlue
 7     ActorBorderColor DeepSkyBlue
 8     LifeLineBorderColor blue
 9     LifeLineBackgroundColor #A9DCDF
10     
11     ParticipantBorderColor DeepSkyBlue
12     ParticipantBackgroundColor DodgerBlue
13     ParticipantFontName Impact
14     ParticipantFontSize 17
15     ParticipantFontColor #A9DCDF
16     
17     ActorBackgroundColor aqua
18     ActorFontColor DeepSkyBlue
19     ActorFontSize 17
20     ActorFontName Aapex
21 }
22 
23 actor User
24 participant "First Class" as A
25 participant "Second Class" as B
26 participant "Last Class" as C
27 
28 User -> A: DoWork
29 activate A
30 
31 A -> B: Create Request
32 activate B
33 
34 B -> C: DoWork
35 activate C
36 C --> B: WorkDone
37 destroy C
38 
39 B --> A: Request Created
40 deactivate B
41 
42 A --> User: Done
43 deactivate A
44 
45 @enduml

技術分享圖片技術分享圖片

(18)填充區設置:可以設定填充區的參數配置。

 1 @startuml
 2 skinparam ParticipantPadding 20
 3 skinparam BoxPadding 10
 4 
 5 box "Foo1"
 6 participant Alice1
 7 participant Alice2
 8 end box
 9 box "Foo2"
10 participant Bob1
11 participant Bob2
12 end box
13 Alice1 -> Bob1 : hello
14 Alice1 -> Out : out
15 @enduml

技術分享圖片

第二部分:《工廠采購》系統對象交互順序

  • 采購員選擇訂貨貨品。
  • 到達訂貨界面,開始接收客戶信息,接收貨品信息,顯示貨品信息。
  • 到達訂貨管理器,創建客戶,取貨品信息,創建訂單。
  • 創建客戶到達客戶區。
  • 取貨品信息到達貨品區。
  • 創建訂單到訂單區。

第三部分:《工廠采購》系統順序圖

 1 @startuml
 2 skinparam sequenceArrowThickness 2
 3 skinparam roundcorner 20
 4 skinparam maxmessagesize 60
 5 skinparam sequenceParticipant underline
 6 
 7 actor 采購員
 8 participant "訂貨界面" as A
 9 participant "訂貨管理器" as B
10 participant "客戶" as C
11 participant "貨品" as D
12 participant "訂單" as E
13 
14 采購員 -> A: 客戶信息()
15 activate A
16 采購員 -> A: 選擇訂貨貨品()
17 activate A
18 
19 A -> B:接收客戶信息()
20 activate B
21 A -> B:接收貨品信息()
22 activate B
23 B --> A: 顯示貨品信息()
24 deactivate B
25 
26 B -> C: 創建客戶()<<create>>
27 activate C
28 B -> D: 取貨品信息()
29 activate D
30 D --> B: 貨品信息()
31 activate D
32 B -> E: 創建訂單()<<create>>
33 activate E
34 @enduml

技術分享圖片

分析工廠采購系統,畫出順序圖