UML作业第四次

一、PlantUML活动图 语法学习小结、图例及用法

1.简单活动图:活动标签(activity label)以冒号开始,以分号结束。活动默认安装它们定义的顺序就行连接。

1
2
3
4
5
@startuml
:My name  is  Dingyi;
:This  is  on defined on
several **lines**;
@enduml

 

2.开始/结束:你可以使用关键字start和stop表示图示的开始和结束。也可以使用 end 关键字。

1
2
3
4
5
6
7
@startuml
start
:My name  is  Dingyi;
:This  is  on defined on
several **lines**;
stop
@enduml

 

1
2
3
4
5
6
7
@startuml
start
:My name  is  Dingyi;
:This  is  on defined on
several **lines**;
end
@enduml

 

3.条件语句:在图示中可以使用关键字if,then和else设置分支测试。标注文字则放在括号中。也可以使用关键字elseif设置多个分支测试。

1
2
3
4
5
6
7
8
9
10
11
12
@startuml
start
 
if  (are you DingYi?) then (yes)
   :give you\packet;
else  (no)
   : get  away
   __pace__ and __love__ instead;
endif
 
stop
@enduml

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@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进行重复循环。

1
2
3
4
5
6
7
8
9
10
11
12
@startuml
 
start
 
repeat
   :read data;
   :generate diagrams;
repeat  while  (more data?)
 
stop
 
@enduml

 

5.while循环:可以使用关键字while和end while进行while循环。

1
2
3
4
5
6
@startuml
while  (check filesize ?) is (not empty)
   :read file;
endwhile (empty)
:close file;
@enduml

 

6.并行处理:你可以使用关键字fork,fork again和end fork表示并行处理。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@startuml
 
start
 
if  (multiprocessor?) then (yes)
   fork
     :Treatment 1;
   fork again
     :Treatment 2;
   end fork
else  (monoproc)
   :Treatment 1;
   :Treatment 2;
endif
 
@enduml

 

7.特殊领域语言(SDL):通过修改活动标签最后的分号分隔符(;),可以为活动设置不同的形状。 
•    |
•    <
•    >
•    /
•    ]
•    }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@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

 

二、语言描述《超市购物》购物活动

  顾客进入商店,选择自己所要购买的商品,并把选好的商品拿到收银台交给收银员。收银员询问顾客是否是会员,如果是会员,索要顾客的会员卡,把会员卡扫描进系统并对会员卡进行验证。然后逐一扫描顾客所选商品的条形码,收款机边接收商品条码,边累加商品金额。扫描完商品信息后,收银员根据收款机上显示的商品金额收货款,然后通过收款机打印售货单。最后收银员把售货单和商品交给顾客,本次购物过程结束。

三、用PlantUML的绘制活动图的脚本程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@startuml
|#AntiqueWhite|顾客|
start
  :选择商品;
  :商品交给收银员;
|收银员|
floating note left: 是否是会员
  if () then ([会员])
    :扫描会员卡;
|收款机|
floating note left: 是否有效
          if  () then ([无效])
          :提示会员卡无效;
      else  ([有效])
          :提示会员卡有效;
          :累计积分;
      endif
|#AntiqueWhite|收银员|
              :扫描商品条码;
  
  else  ([非会员])
|收银员|
  :扫描商品条码;
  endif
|收款机|
  :接收商品条码;
  :统计商品金额;
|收银员|
  while (还有商品否?)  is  ([有])
    :扫描商品条码;
    endwhile ([无])
|顾客|
  :交付货款;
|收银员|
  :接受货款;
|收款机|
  :打印售货单;
|收银员|
  :货单及货品交给顾客;
|顾客|
  :接受货单及货品;
 
  stop
@enduml

四、绘制的活动图

猜你喜欢

转载自www.cnblogs.com/Liuhuaqing/p/10823114.html