第一部分:活动图语法测试
(1)简单活动图:活动标签(activity label)以冒号开始,以分号结束。活动默认安装它们定义的顺序就行链接。spa
1 @startuml 2 :Hello world; 3 :This is on defined on 4 several **lines**; 5 @enduml
(2)开始/结束:你能够使用关键字start
和stop
表示图示的开始和结束。3d
1 @startuml 2 start 3 :Hello world; 4 :This is on defined on 5 several **lines**; 6 stop 7 @enduml
@startuml start :Hello world; :This is on defined on several **lines**; end @enduml
(3)条件语句:在图示中能够使用关键字if
,then
和else
设置分支测试。标注文字则放在括号中。code
@startuml start if (Graphviz installed?) then (yes) :process all\ndiagrams; else (no) :process only __sequence__ and __activity__ diagrams; endif stop @enduml
@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
(4)重复循环:你能够使用关键字repeat
和repeatwhile
进行重复循环。orm
@startuml start repeat :read data; :generate diagrams; repeat while (more data?) stop @enduml
(5)while循环:能够使用关键字while
和end while
进行while循环。还能够在关键字endwhile
后添加标注,还有一种方式是使用关键字is
。blog
@startuml start while (data available?) :read data; :generate diagrams; endwhile stop @enduml
@startuml while (check filesize ?) is (not empty) :read file; endwhile (empty) :close file; @enduml
(6)并行处理:你能够使用关键字fork
,fork again
和end fork
表示并行处理。ip
@startuml start if (multiprocessor?) then (yes) fork :Treatment 1; fork again :Treatment 2; end fork else (monoproc) :Treatment 1; :Treatment 2; endif @enduml
(7)注释:it
@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
(8)箭头:io
使用->
标记,你能够给箭头添加文字或者修改箭头颜色。同时,你也能够选择点状 (dotted),条状(dashed),加粗或者是隐式箭头form
@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
(9)链接器(Connector):能够使用括号定义链接器。
@startuml
start
:Some activity;
(A)
detach
(A)
:Other activity;
@enduml
(10)组合(grouping):经过定义分区(partition),你能够把多个活动组合(group)在一块儿。
@startuml start partition Initialization { :read config file; :init internal variable; } partition Running { :wait for user interaction; :print information; } stop @enduml
(11)分离(detach):能够使用关键字detach
移除箭头。
@startuml :start; fork :foo1; :foo2; fork again :foo3; detach endfork if (foo4) then :foo5; detach endif :foo6; detach :foo7; stop @enduml
(12)特殊领域语言(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
第二部分:分析《超市购物》系统
超市购物系统拥有三个部分:顾客、收银员、收款机。
顾客进入商店,选择本身所要购买的商品,并把选好的商品拿到收银台交给收银员。
收银员询问顾客是不是会员,若是是会员,索要顾客的会员卡,把会员卡扫描进系统并对会员卡进行验证。
而后逐一扫描顾客所选商品的条形码,收款机边接收商品条码,边累加商品金额。
扫描完商品信息后,收银员根据收款机上显示的商品金额收货款,而后经过收款机打印售货单。
最后收银员把售货单和商品交给顾客,本次购物过程结束。
第三部分:《超市购物》活动图
1 @startuml 2 start 3 :选择商品; 4 :商品交给收银员; 5 if (是不是会员) then (会员) 6 :扫描会员卡; 7 if (是否有效) then (无效) 8 :提示会员卡无效; 9 else (有效) 10 :提示会员卡有效; 11 endif 12 :扫描商品条码; 13 14 else (非会员) 15 :扫描商品条码; 16 endif 17 :接收商品条码; 18 :统计商品金额; 19 while(还有商品否?) is (有) 20 :扫描商品条码; 21 endwhile (无) 22 :交付货款; 23 :接受货款; 24 :打印售货单; 25 :货单及货品交给顾客; 26 :接受货单及货品; 27 28 29 stop 30 @enduml