uml使用(二)–組件圖編寫
一、簡介
這一節介紹常用組件圖的編寫,組件圖可以描述項目架構。組件圖中很多標識與時序圖中同樣,這裏主要介紹不同的地方。
二、組件圖知識點
2.1、文檔官網地址
文檔官網地址:http://plantuml.com/zh/component-diagram
2.2、開始結束符
uml開始和結束是一樣的,都是@startuml和@enduml。
2.3、組件
用[]或component關鍵字來定義組件,同時可以使用as起別名,可以使用RGB或顏色來標識組件。
另外還可使用note left of , note right of , note top of , note bottom of對組件進行註釋 ,如:
component 組件1 #green
[組件2]
[組件3] as cp3
[組件4]
note left of [組件41]:這是註釋
note bottom of [組件42]
這是另一種
註釋方式
end note
2.4、接口
用()或interface來定義接口。如:
() 接口1
interface 接口2
2.5、線條及箭頭
…表示豎向虛線,.表示橫向虛線;
–表示豎向實線,-表示橫向實線
>和<箭頭指向具體的組件,>>和<<時箭頭爲實心三角形,不加則沒有箭頭。
在–或…中,使用關鍵字up、down、left、right可以改變箭頭方向。
組件後加冒號,可添加消息內容、
如:
接口3 .. [組件4]:請求1
接口4 . [組件4]
[組件4] -->> [組件5]:請求2
[組件5] -> [組件6]
[組件6] -up-> [組件7]
2.6、模塊
模塊樣式有node、frame、package、cloud(雲)、database(數據庫)、folder,使用如:
folder folder標題 {
[組件8] -left-> [組件9]
}
frame frame標題 {
[組件10] -right-> [組件11]
}
package "package標題" {
[組件12] -left-> [組件13]
}
database database標題 {
[組件14] -down-> [組件15]
}
node node標題 {
[組件16] -right-> [組件17]
}
cloud cloud標題 {
[組件18] -right-> [組件19]
}
三、完整示例
下面給出個完整示例。
@startuml
title:這是標題
() 接口1
folder folder標題 {
[組件a1] -> [組件a2]
}
frame frame標題 {
[組件b1] <- [組件b2]
}
package "package標題" {
[組件c1] -> [組件c2]
[組件c2] -> [組件c3]
}
database database標題 {
[組件d1] -down-> [組件d2]
}
node node標題 {
[組件e1] -left-> [組件e2]
}
cloud cloud標題 {
[組件f1] -right-> [組件f2]
}
接口1 --> [組件a1]
component 組件a1 #green
note left of [組件d1]:這是註釋
[組件a2] -->[組件b2]
[組件b1] -down->[組件c1]
[組件c1] -->[組件e1]
[組件c2] -down->[組件f1]
[組件c3] -down->[組件d1]
@enduml
四、編寫工具
同時序圖一樣,可在idea中使用plantuml插件(需要安裝渲染工具Graphviz)。