第1部分:活动图语法
(1)简单活动图:活动标签(activity label )以冒号开头,以分号结尾。 活动的默认安装允许您按照定义的顺序进行连接。
1 @startuml2 :Hello world; 3: thisisondefinedon4several * * lines * *; 5 @enduml
)2)开始/结束)关键字start和stop可以用来表示图标的开始和结束。
1 @ start UML2start : hello world; 4: thisisondefinedon5several * * lines * *; 6 stop7 @enduml
@startuml
开始
:健康世界;
:This is on defined on
several**lines**;
结束
@enduml
(3)条件句)图中可以使用关键字if、then、else设定分支测试。 尺寸值括在括号中。
@startuml
graphviz installed (开始if )? ((then ) yes ) )。
:处理所有 n诊断程序; 是else (否)
:仅限进程
_ _ sequence _ _ and _ _ activity _ _ diagrams;
最终幻想
停止
@enduml
@startuml
开始if (condition a ) then (是) )。
:文本1;
Elseif(conditionb ) then (是) )。
:文本2;
停止
Elseif(conditionc ) then (是) )。
:文本3;
Elseif(conditiond ) then (是) )。
:文本4; 是else(nothing )
:文本;
最终幻想
停止
@enduml
(4)重复循环)可以使用关键字repeat和repeatwhile重复循环。
@startuml
开始
重复
:读取数据;
:生成诊断程序;
repeat while (模式数据? )
停止
@enduml
(5) while循环:可以使用关键字while和end while进行while循环。 也可以在关键字endwhile之后添加标注。 另外,还有使用关键字is的方法。
@startuml
开始while (数据可用? )
:读取数据;
:生成诊断程序;
结束while
停止
@enduml
@ startumlwhile (检查文件? (is ) notempty )
3360引导文件;
结束while (empty )
:关闭文件;
@enduml
)6)并行处理)可以使用关键字fork、fork again和end fork表示并行处理。
@startuml
多处理器(start if )? ((then ) yes ) )。
福瑞克
:Treatment1;
fork again
:Treatment2;
最终订单(mono proc ) )。
:Treatment1;
:Treatment2;
最终幻想
@enduml
(7)评论:
@startuml
开始
:foo1;
浮动笔记型电脑: this is a note
:foo2;
诺托轻型
thisnoteisonseveral//lines//and can
contain HTML
=====
>* Calling the method ""foo()""is prohibitedend note
stop
@enduml
(8)箭头:
使用->标记,你可以给箭头添加文字或者修改箭头颜色。同时,你也可以选择点状 (有魅力的超短裙),条状(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,有魅力的超短裙]->: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 {
:waitforuser interaction;
:print information;
}
stop
@enduml
(11)分离(detach):可以使用关键字detach移除箭头。
@startuml
:start;
fork
:foo1;
:foo2;
fork again
:foo3;
detach
endforkif(foo4) then
:foo5;
detach
endif
:foo6;
detach
:foo7;
stop
@enduml
(12)特殊领域语言(SDL):通过修改活动标签最后的分号分隔符(;),可以为活动设置不同的形状。
@startuml
:Ready;
:next(o)|:Receiving;
split
:nak(i)<:ack>split again
:ack(i)<:next>
on several line|:i := i + 1]
:ack(o)>split again
:err(i)<:nak>split again
:foo/split again
:i> 5}
stop
end split
:finish;
@enduml
第二部分:分析《超市购物》系统
超市购物系统拥有三个部分:顾客、收银员、收款机。
顾客进入商店,选择自己所要购买的商品,并把选好的商品拿到收银台交给收银员。
收银员询问顾客是否是会员,如果是会员,索要顾客的会员卡,把会员卡扫描进系统并对会员卡进行验证。
然后逐一扫描顾客所选商品的条形码,收款机边接收商品条码,边累加商品金额。
扫描完商品信息后,收银员根据收款机上显示的商品金额收货款,然后通过收款机打印售货单。
最后收银员把售货单和商品交给顾客,本次购物过程结束。
第三部分:《超市购物》活动图
1 @startuml2 start3 :选择商品;4 :商品交给收银员;5 if(是否是会员) then (会员)6 :扫描会员卡;7 if(是否有效) then (无效)8 :提示会员卡无效;9 else(有效)10 :提示会员卡有效;11 endif12 :扫描商品条码;13
14 else(非会员)15 :扫描商品条码;16 endif17 :接收商品条码;18 :统计商品金额;19 while(还有商品否?) is (有)20 :扫描商品条码;21 endwhile (无)22 :交付货款;23 :接受货款;24 :打印售货单;25 :货单及货品交给顾客;26 :接受货单及货品;27
28
29 stop30 @enduml