UML之活动图介绍

活动图,也就是UML中来描述活动、流程的建模工具。

在这里插入图片描述

The Activity Diagram can help to describe the flow of control of the target system, such as the exploring complex business rules and operations, describing the use case also the business process.

本文末尾有推荐的软件下载,帮助完成 Activity 活动图建模。建议读者安装后,一边实践,一边学习概念。

主要组成元素

为了描述对象,流程控制,活动图抽象很多概念,每个概念尤其特定的定义,图标,方便实现可视化工具,对流程进行描述和实现。
在这里插入图片描述

下面对主要元素进行概述。

活动状态图(Activity)

活动状态用于表达状态机中的非原子的运行,其特点如下:

(1) 活动状态可以分解成其他子活动或者动作状态。

(2) 活动状态的内部活动可以用另一个活动图来表示。

(3) 和动作状态不同,活动状态可以有入口动作和出口动作,也可以有内部转移。

(4) 动作状态是活动状态的一个特例,如果某个活动状态只包括一个动作,那么它就是一个动作状态。

UML中活动状态和动作状态的图标相同,但是活动状态可以在图标中给出入口动作和出口动作等信息。

在这里插入图片描述

动作(Actions)

动作是指原子的,不可中断的动作,并在此动作完成后通过完成转换转向另一个状态。动作状态有如下特点:

(1) 动作是原子的,它是构造活动图的最小单位。

(2) 动作是不可中断的。

(3) 动作是瞬时的行为。

(4) 动作可以有入转换,入转换既可以是动作流,也可以是对象流。动作状态至少有一条出转换,这条转换以内部的完成为起点,与外部事件无关。

(5) 动作状态与状态图中的状态不同,它不能有入口动作和出口动作,更不能有内部转移。

(6) 在一张活动图中,动作允许多处出现。

UML中的动作状态图用平滑的圆角矩形表示,如下:

在这里插入图片描述

动作状态约束(Action Constraints): 用来约束动作状态。如下图展示了动作状态的前置条件和后置条件。

对象 / 业务对象 (Object)

业务对象(Business Object),是不同动作流转时,交换/传递的数据,通常根据业务需求设定结构化的字段。在动作中,可以调整业务字段,也常被简称为BO。

A business object consists of structured data that is exchanged between actions (see Messages in UML). Generally, the business object that is the output of one action is simultaneously the input of another action.

在这里插入图片描述

使用长方形,直角形状表示。

开始节点(Initial Node)

开始节点:表示成实心黑色圆点

在这里插入图片描述

终止节点(Final Node)

分为活动终止节点(activity final nodes)和流程终止节点(flow final nodes)。

流程终止节点表示是子流程的结束;

在这里插入图片描述

活动终止节点表示整个活动的结束。
在这里插入图片描述

活动(Activity)是包含一个或多个流程(Flow)的,一个活动的结束,代表其中的所有流程也结束。

流程控制

流程控制即状态行进的状态管理,动作之间的交接。
在这里插入图片描述

动作流(Control Flow)

连接动作,动作之间的转换称之为动作流,活动图的转换用带箭头的直线表示,箭头的方向指向转入的方向。

在这里插入图片描述

对象流(Object Flows)

对象流是动作状态或者活动状态与对象之间的依赖关系,表示动作使用对象或动作对对象的影响。对象流是描述了一个流里可以包含的数据结构。

用活动图描述某个对象时,可以把涉及到的对象放置在活动图中并用一个依赖将其连接到进行创建、修改和撤销的动作状态或者活动状态上,对象的这种使用方法就构成了对象流。

对象流中的对象有以下特点:

(1) 一个对象可以由多个动作操作。

(2) 一个动作输出的对象可以作为另一个动作输入的对象。

(3) 在活动图中,同一个对象可以多次出现,它的每一次出现表面该对象正处于对象生存期的不同时间点。

对象流用带有箭头的虚线表示。如果箭头是从动作状态出发指向对象,则表示动作对对象施加了一定的影响。施加的影响包括创建、修改和撤销等。如果箭头从对象指向动作状态,则表示该动作使用对象流所指向的对象。

状态图中的对象用矩形表示,矩形内是该对象的名称,名称下的方括号表明对象此时的状态。

The object flow describes the flow of objects and data within activities.

分支与合并(Decision and Merge Nodes)

分支与合并用菱形表示

分支

在这里插入图片描述
分支中,只有一个输出有效。

Decision can have decision input behavior. Decision input behaviors were introduced in UML to avoid redundant recalculations in guards. In this case each data token is passed to the behavior before guards are evaluated on the outgoing edges. The output of the behavior is available to each guard.
在这里插入图片描述

合并

在这里插入图片描述

Decision may also have decision input flow. In this case the tokens offered on the decision input flow that are made available to the guard on each outgoing edge determine whether the offer on the regular incoming edge is passed along that outgoing edge.

分叉与汇合(Fork and Join Nodes)

分为水平风向和垂直方向。

对象在运行时可能会存在两个或多个并发运行的控制流,为了对并发的控制流建模,UML中引入了分叉与汇合的概念。分叉用于将动作流分为两个或多个并发运行的分支,而汇合则用于同步这些并发分支,以达到共同完成一项事务的目的。

分叉

在这里插入图片描述

分叉的各个输出都进行,同时进行。

Fork node is a control node that has one incoming edge and multiple outgoing edges and is used to split incoming flow into multiple concurrent flows.
The notation for a fork node is a line segment with a single activity edge entering it, and two or more edges leaving it.

汇合

在这里插入图片描述

Join node is a control node that has multiple incoming edges and one outgoing edge and is used to synchronize incoming concurrent flows.
The notation for a join node is a line segment with several activity edges entering it, and only one edge leaving it.

汇合时,可以指定条件,进入下一步,此时有的分叉可能还没有完结。

在这里插入图片描述

异常处理

当受保护的活动发生异常时,触发异常处理节点。
包括异常动作(Exception Handler),和连接异常动作(Interrupting Flow)。

Exception Handler

处理异常的动作。
在这里插入图片描述

The Exception Handler element defines the group of operations to carry out when an exception occurs. In an Activity diagram, the protected element can contain a set of operations and is connected to the exception handler via an Interrupt Flow connector. Any defined error contained within an element’s parts can trigger the flow to move to an exception.

Interrupting Flow

将发生异常的动作,连接到异常处理。
在这里插入图片描述

The Interrupt Flow is a connection used to define the two UML concepts of connectors for Exception Handler and Interruptible Activity Region. An Interrupt Flow is a type of activity edge. It is typically used in an Activity diagram, modeling an active transition. It is rendered as a lightning-bolt.

泳道(Partition)

泳道将活动图中的活动划分为若干组,并把每一组指定给负责这组活动的业务组织,即对象。在活动图中,泳道区分了负责活动的对象,它明确地表示了哪些活动是由哪些对象进行的。在包含泳道的活动图中,每个活动只能明确地属于一个泳道。

泳道是用垂直实线绘出,垂直线分隔的区域就是泳道。在泳道的上方可以给出泳道的名字或对象的名字,该对象负责泳道内的全部活动。泳道没有顺序,不同泳道中的活动既可以顺序进行也可以并发进行,动作流和对象流允许穿越分隔线。

在这里插入图片描述

An activity partition is activity group for actions that have some common characteristic. Activity partition may be shown using a swimlane notation - with two, usually parallel lines, either horizontal or vertical, and a name labeling the partition in a box at one end.

建模工具:StarUML

StarUML 是一个轻巧,跨平台,专注的UML工具,对Activity的支持也很完善和标准,推荐使用。

在这里插入图片描述

下载地址:http://staruml.io/download

BPMN 和 UML Activity 的比较

BPMN作为另一个描述流程,尤其是应用在业务流程(BPM)中的建模规范,和 UML Activity 是什么关系呢?有什么异同?

UML ActivityBPMN Business Process
The starting point is defined by an Initial Node. No method of specifying why the Activity was started is available.The starting point is defined by a Start Event. This implies a specific cause for the Activity to start, although it could be unspecified.
The basic behavior unit in an Activity is the Action element. UML provides many different forms of Actions, although the simulation makes use of a small subset of these.The basic behavior unit in an Activity is the Activity element. A number of different Task Types are available. These typically describe different methods of execution (for example Manual) as opposed to what happens.
A Control Flow is used to connect the elements on an Activity diagram. A distinguishing feature is that only a single Control Flow can be followed from any node, except for an explicit Fork Node. To restrict flow on a Control Flow, add a Guard.A Sequence Flow is used to connect the elements on a Business Process diagram. These differ from UML Activity diagrams in that all valid sequence flows are taken by default. To restrict flow on a Sequence Flow set the conditionType Tagged Value to ‘Expression’ and create the script in the conditionExpression Tagged Value.
A Decision node is used to explicitly model a decision being made. A Merge node, which uses the same syntax is used when the potential flows are combined back into one.A Gateway node set to ‘Exclusive’ is used when a single path must be selected. It is also used to combine the potential flows again. A direction can be specified as ‘Converging’ or ‘Diverging’ to explicitly select between the two modes.
A Fork node is used to concurrently execute multiple nodes, while a Join node, using the same syntax is used to wait for all incoming flows to become available and leave with a single flow.A Gateway node set to ‘Parallel’ is used to explicitly model concurrent execution of multiple nodes. It is also used to wait for all incoming flows to become available and leave with a single flow. A direction can be specified as ‘Converging’ or ‘Diverging’ to explicitly select between the two modes.
There is no allowance for concurrently executing only some outputs from a node for UML Activities. If you needed this you add later Control Flows with the appropriate Guards.A Gateway node set to Inclusive is used to explicitly model the situation where all outgoing flows with a true condition are executed concurrently.
A Call Behavior Action is used when behavior needs to be further decomposed by referring to an external activity.Activity elements are set as a CallActivity Sub-Process when behavior needs to be further decomposed by referring to an external activity.
Activity Action Call Behavior Action.Activity elements are set as an Embedded Sub-Process when behavior needs to be further decomposed without referring to an external activity.

总结

本文只介绍了常用的 UML 活动图建模元素,更多详细内容,请延伸阅读下面参考文章。

参考文章

Comparison of UML Activities and BPMN Processes

Activity diagram

UML Activity Diagrams Reference

UML建模之活动图介绍(Activity Diagram)

Interrupt Flow

Activity Diagrams

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值