UML做業第六次:分析系統,繪製順序圖

UML做業第六次:分析系統,繪製順序圖學習

1、做業要求及步驟

step1:學習PlantUML順序圖繪製方法

step2:以《工廠採購》系統爲例,分析系統中的對象、消息。

step3: 參照教材P148頁的圖8.5,分析對象的交互;

step4:用PlantUML 《工廠採購》系統的對象交互腳本;

step5:在線繪製UML圖

1、活動圖語法測試

活動標籤(activity label)以冒號開始,以分號結束,文本格式支持creole wiki語法。,活動默認安裝它們定義的順序就行鏈接。this

@startuml
:Hello world;
:This is on defined on
several **lines**;
@enduml

開始/結束

可使用關鍵字startstop表示圖示的開始和結束。code

@startuml
start
:Hello world;
:This is on defined on
several **lines**;
stop
@enduml

也可使用 end 關鍵字。orm

@startuml
start
:Hello world;
:This is on defined on
several **lines**;
end
@enduml

條件語句

在圖示中可使用關鍵字ifthenelse設置分支測試。標註文字則放在括號中。對象

@startuml

start

if (Graphviz installed?) then (yes)
  :process all\ndiagrams;
else (no)
  :process only
  __sequence__ and __activity__ diagrams;
endif

stop

@enduml

也可使用關鍵字elseif設置多個分支測試。blog

@startuml
start
if (condition A) then (yes)
  :Text 1;
elseif (condition B) then (yes)
  :Text 2;
  stop
elseif (condition C) then (yes)
  :Text 3;
elseif (condition D) then (yes)
  :Text 4;
else (nothing)
  :Text else;
endif
stop
@enduml

 

重複循環

可使用關鍵字repeatrepeatwhile進行重複循環。ip

@startuml

start

repeat
  :read data;
  :generate diagrams;
repeat while (more data?)

stop

@enduml
while循環

可使用關鍵字whileend while進行while循環。ci

@startuml

start

while (data available?)
  :read data;
  :generate diagrams;
endwhile

stop

@enduml

還能夠在關鍵字endwhile後添加標註,還有一種方式是使用關鍵字isit

@startuml
while (check filesize ?) is (not empty)
  :read file;
endwhile (empty)
:close file;
@enduml

並行處理

可使用關鍵字forkfork againend fork表示並行處理。

@startuml

start

if (multiprocessor?) then (yes)
  fork
	:Treatment 1;
  fork again
	:Treatment 2;
  end fork
else (monoproc)
  :Treatment 1;
  :Treatment 2;
endif

@enduml

註釋

文本格式支持creole wiki語法。

A note can be floating, using floating keyword.

@startuml

start
:foo1;
floating note left: This is a note
:foo2;
note right
  This note is on several
  //lines// and can
  contain <b>HTML</b>
  ====
  * Calling the method ""foo()"" is prohibited
end note
stop

@enduml

 顏色

能夠爲活動(activity)指定一種顏色。

@startuml

start
:starting progress;
#HotPink:reading configuration files
These files should edited at this point!;
#AAAAAA:ending of the process;

@enduml

箭頭

使用->標記,能夠給箭頭添加文字或者修改箭頭顏色。

同時,也能夠選擇點狀 (dotted),條狀(dashed),加粗或者是隱式箭頭

@startuml
:foo1;
-> You can put text on arrows;
if (test) then
  -[#blue]->
  :foo2;
  -[#green,dashed]-> The text can
  also be on several lines
  and **very** long...;
  :foo3;
else
  -[#black,dotted]->
  :foo4;
endif
-[#gray,bold]->
:foo5;
@enduml

鏈接器(Connector)

可使用括號定義鏈接器。

@startuml
start
:Some activity;
(A)
detach
(A)
:Other activity;
@enduml

組合(grouping)

經過定義分區(partition),你能夠把多個活動組合(group)在一塊兒。

@startuml
start
partition Initialization {
	:read config file;
	:init internal variable;
}
partition Running {
	:wait for user interaction;
	:print information;
}

stop
@enduml

泳道(Swimlanes)

你可使用管道符|來定義泳道。

還能夠改變泳道的顏色。

@startuml
|Swimlane1|
start
:foo1;
|#AntiqueWhite|Swimlane2|
:foo2;
:foo3;
|Swimlane1|
:foo4;
|Swimlane2|
:foo5;
stop
@enduml

分離(detach)

可使用關鍵字detach移除箭頭。

@startuml
 :start;
 fork
   :foo1;
   :foo2;
 fork again
   :foo3;
   detach
 endfork
 if (foo4) then
   :foo5;
   detach
 endif
 :foo6;
 detach
 :foo7;
 stop
@enduml

特殊領域語言(SDL)

經過修改活動標籤最後的分號分隔符(;),能夠爲活動設置不一樣的形狀。

  • |
  • <
  • >
  • /
  • ]
  • }
@startuml
:Ready;
:next(o)|
:Receiving;
split
 :nak(i)<
 :ack(o)>
split again
 :ack(i)<
 :next(o)
 on several line|
 :i := i + 1]
 :ack(o)>
split again
 :err(i)<
 :nak(o)>
split again
 :foo/
split again
 :i > 5}
stop
end split
:finish;
@enduml
2、分析《工廠採購》系統
一、採購員選擇採購貨品

二、到定貨界面,接收客戶信息,接收貨品信息,顯示貨品信息

三、到定貨管理器,建立客戶,取貨品信息,建立訂單

四、建立客戶到客戶區,取貨品信息到貨品區,建立訂單到訂單區

3、《工廠採購》的系統腳本
@startuml
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
4、《工廠採購》系統的UML圖
相關文章
相關標籤/搜索