Activity Diagrams

Activity diagrams are often used to model business processes. They simply and quite plainly show how things work, and so function as a good aid to discussions of aspects of the workflow with the domain experts. These are less abstract than the often used object-oriented state machine diagrams.

Activity diagrams are an essential part of the modeling process. They are used to clarify complicated use cases, illustrate control among objects, or to show the logic of an algorithm. The UML 2.0 metamodel substantially refined and improved Activity diagrams; whereas the UML 1.4 Activity diagram was a subclass of State Machine, UML 2.0 defined a separate metamodel, making the diagram much more suited to the job of describing behavior.

The following example shows an activity diagram that depicts the rules and the process of reserving a car. In the following example, StattAuto will not accept a reservation if vehicles are not available, etc. Take a closer look for yourself in order to become more familiar with the notation.

Figure 10-8. An Activity diagram.

Creating Activity Diagrams

An Activity can have multiple diagrams. An activity diagram belongs to exactly one activity. The activities and diagrams are created differently based upon the element selected:

  1. BehavioredClassifier Selected - When a BehavioredClassifier such as a class, a collaboration, or a use case is selected, a new activity is created with the BehavioredClassifier as its owner. A new Activity Diagram is then created with the new activity as its parent.

  2. Activity Selected - When an existing activity is selected, a new Activity Diagram is created with the selected activity as its parent.

  3. CallAction Selected - When a CallAction is selected, a new activity is created with the same parent as the selected CallAction, and a new Activity Diagram is created for the new activity.

  4. For Any Other Selection - A new collaboration is created in the namespace of the currently selected element, an activity is created within this collaboration, and an Activity Diagram is created for this activity.

Using the Spacer Feature

The spacer increases or decreases the amount of space between elements along a single axis. To use this handy feature, click on the Spacer button in the toolbar, then click and drag where you would like to create whitespace. All elements on the motion side of the cursor will be nudged in the direction of the cursor.

Actions

Call Action

A CallAction is an abstract class for actions that invoke behavior and receive return values. - OMG UML 2.0 Superstructure Specification p. 259

Send Signal Action

SendSignalAction is an action that creates a signal instance from its inputs, and transmits it to the target object, where it may cause the firing of a state machine transition or the execution of an activity. - OMG UML 2.0 Superstructure Specification p. 302

Accept Event Action

An AcceptEventAction is an action that waits for the occurrence of an event meeting specified conditions. - OMG UML 2.0 Superstructure Specification p. 249

Nodes

Input and Output Pins

A pin is a typed element and multiplicity element that provides values to actions and accepts result values from them. - OMG UML 2.0 Superstructure Specification p. 282

An input pin is a pin that holds input values to be consumed by an action. - OMG UML 2.0 Superstructure Specification p. 273

An output pin is a pin that holds output values produced by an action. - OMG UML 2.0 Superstructure Specification p. 281

Object Node

An object node is an activity node that indicates an instance of a particular classifier, possibly in a particular state, may be available at a particular point in the activity. Object nodes can be used in a variety of ways, depending on where objects are flowing from and to, as described in the semantics section. - OMG UML 2.0 Superstructure Specification p. 422

Initial, Final Activity, and Final Flow Nodes

An initial node is a control node at which flow starts when the activity is invoked. - OMG UML 2.0 Superstructure Specification p. 406

An activity final node is a final node that stops all flows in an activity. - OMG UML 2.0 Superstructure Specification p. 356

A flow final node is a final node that terminates a flow. - OMG UML 2.0 Superstructure Specification p. 403

Fork and Join Nodes

A fork node is a control node that splits a flow into multiple concurrent flows. - OMG UML 2.0 Superstructure Specification p. 404

A join node is a control node that synchronizes multiple flows. - OMG UML 2.0 Superstructure Specification p. 411

Decision and Merge Nodes

A decision node is a control node that chooses between outgoing flows. - OMG UML 2.0 Superstructure Specification p. 387

A merge node is a control node that brings together multiple alternate flows. It is not used to synchronize concurrent flows but to accept one among several alternate flows. - OMG UML 2.0 Superstructure Specification p. 416

Activity Parameter Node

Activity Parameter Node

An activity parameter node is an object node for inputs and outputs to activities. - OMG UML 2.0 Superstructure Specification p. 363

To create an Activity Parameter Node, simply click the 'Activity Parameter Node' button in the toolbar, then click anywhere in the Activity diagram. The new node will be placed along the edge of the activity, and can be dragged along to the perimeter to the desired location.

Flow

Object and Control Flow

An object flow is an activity edge that can have objects or data passing along it. - OMG UML 2.0 Superstructure Specification p. 418

A control flow is an edge that starts an activity node after the previous one is finished. - OMG UML 2.0 Superstructure Specification p. 382

Exception Handler

An exception handler is an element that specifies a body to execute in case the specified exception occurs during the execution of the protected node. - OMG UML 2.0 Superstructure Specification p. 390

To create an exception handler

  1. Click the Exception Handler button in the toolbar

  2. Click and drag from an action to another action or an input pin.

    Alternatively, a new HandlerBody node with input pin can be created by clicking and dragging from the action to wherever the new node should be created.

    In both cases, the resulting exception handler will have the same type as the input pin.

Activity Groups

Activity Partitions

An activity partition is a kind of activity group for identifying actions that have some characteristic in common. They often correspond to organizational units in a business model. They may be used to allocate characteristics or resources among the nodes of an activity. - OMG UML 2.0 Superstructure Specification p. 367

Partitions are the UML 2.0 version of the swimlane functionality that divides and clarifies an activity diagram according to certain characteristics. Quite often, this is used to delineate responsibility between roles.

Partitions are not limited in number or orientation; that is, you may have any number of partitions in both the X and Y directions. The above example shows two vertical partitions.

Creating an Activity Partition

  1. Click on the Activity Partition button in the toolbar, then click anywhere in the activity diagram. Any existing elements can now be dragged into the appropriate partitions.

  2. Partitions can be added or deleted by clicking the associated rapid button.

    In this case, clicking the rightmost plus sign will create a new vertical partition between the Clerk and Manager Partitions. The left button will create a vertical partition to the left of Clerk, and the button below will create a horizontal partition:

Activity Partition Display

Partitions can be resized just as any other element. Select the partition and use the handles to adjust.

A partition can represent a theoretical category that is not in the model, or it can represent a concrete idea that has already been modeled. In the former case, the name of the partition is important to clearly convey exactly what is being presented in the model. To name a partition, simply enter the desired name in the Properties tab or double-click the name in the diagram to edit inline.

But it will more often be the case that the partition will represent something that is already in the model, such as an actor from a use case diagram. It is more robust and clearer within the model if the display name of the partition is the result of an actual link to that element.

In the Properties tab of the partition, select the appropriate element from the 'Represents' dropdown list. If the name of the partition is empty, the name of this selected element will display. If the name of the partition exists, then the explicit name will display.

Two Dimensional Activity Partitions

Activity Partitions may also be created in two dimensions - that is, both horizontal and vertical partitions may be used at the same time.

Interruptable Activity Regions

An interruptable region contains activity nodes. When a token leaves an interruptable region via edges designated by the region as interrupting edges, all tokens and behaviors in the region are terminated. - OMG UML 2.0 Superstructure Specification p. 367

An interruptable region is denoted with a broken line, just like other activity groups. To create the region, click the 'Interruptable Region' button in the toolbar, then click and drag in the diagram to make the region the appropriate size.

Edges

Two types of edges may cross the boundaries of the interruptable region: 'normal' activity edges that do not terminate other token flows, and 'interruptable' edges that are marked with with an icon similar to the exception handler icon. (This is potentially confusing, but UML 2.0 specifies this notation.)

To mark and edge as interruptable, either use the rapid button that appears when hovering over the edge, or select the 'Is interruptable edge' checkbox in the Properties tab.

Expansion Regions

An expansion region is a structured activity region that executes multiple times corresponding to elements of an input collection. - OMG UML 2.0 Superstructure Specification p. 395

To create an expansion region, select the 'Expansion Region' button from the toolbar, then click in the diagram. The size of the expansion region can be adjusted with the handles.

Each expansion region has a mode, which can be changed using the rapid buttons or by adjusting the radio buttons in the Properties tab. Rapid buttons also exist to create the expansion nodes, which are essentially specialized input and output pins.

Conditional Nodes

A conditional node is a structured activity that represents an exclusive choice among some number of alternatives. - OMG UML 2.0 Superstructure Specification p. 380

Conditional nodes convey 'if - then - else' logic. To create a conditional node, select the 'Conditional Node' button from the toolbar, then click in the diagram. The size of the conditional node can be adjusted with the handles.

Loop Node

A loop node is a structured activity that represents a loop with setup, test, and body sections. - OMG UML 2.0 Superstructure Specification p. 414

The loop node models a 'for - while - do' loop. To create a loop node, select the 'Loop Node' button from the toolbar, then click in the diagram. The size of the loop node can be adjusted with the handles.

Diagram Elements

Toolbar

Select

Add or remove space between elements

Call Action

Send Signal Action

Accept Event Action

Object Node

Activity Edge

Exception Handler

Initial Node

Activity Final Node

Flow Final Node

Fork Node

Join Node

Decision Node

Merge Node

Activity Parameter Node

Vertical Activity Partition

Horizontal Activity Partition

Matrix Activity Partition

Conditional Node

Loop Node

Structured Activity Node

Expansion Region

Interruptable Activity Region

Comment

Connect Comment to Element

Text

Shape

Repaint

Do layout

Update layout

Zoom to 100%

Zoom to Fit

Zoom to Selection