Terms and Concepts
An activity diagram shows the flow from activity to activity. An activity is an ongoing nonatomic execution within a state machine. The execution of an activity ultimately expands into the execution of individual actions, each of which may change the state of the system or communicate messages. Actions encompass calling another operation, sending a signal, creating or destroying an object, or some pure computation such as evaluating an expression. Graphically, an activity diagram is a collection of nodes and arcs.
Common Properties
An activity diagram is a kind of diagram and shares the same common properties as do all other diagramsa name and graphical contents that are a projection into a model. What distinguishes an interaction diagram from other kinds of diagrams is its content.
The general properties of diagrams are discussed in Chapter 7 . |
Contents
Activity diagrams commonly contain
States, transitions, and state machines are discussed in Chapter 22; objects are discussed in Chapter 13 . |
Like all other diagrams, activity diagrams may contain notes and constraints.
Actions and Activity Nodes
In the flow of control modeled by an activity diagram, things happen. You might evaluate some expression that sets the value of an attribute or that returns some value. Alternately, you might call an operation on an object, send a signal to an object, or even create or destroy an object. These executable, atomic computations are called actions. As Figure 20-2 shows, you represent an action using a rounded box. Inside that shape, you may write an expression.
Figure 20-2. Actions

Attributes and operations are discussed in Chapters 4 and 9; signals are discussed in Chapter 21; creation and destruction of objects are discussed in Chapter 16; states and state machines are discussed in Chapter 22 . |
Modeling time and space is discussed in Chapter 24 . |
Figure 20-3. Activity Nodes

Control Flows
When an action or activity node completes execution, flow of control passes immediately to the next action or activity node. You specify this flow by using flow arrows to show the path of control from one action or activity node to the next action or activity node. In the UML, you represent a flow as a simple arrow from the predecessor action to its successor, without an event label, as Figure 20-4 shows.
Figure 20-4. Completion Transitions

Branching
Simple, sequential flows are common, but they aren't the only kind of path you'll need to model a flow of control. As in a flowchart, you can include a branch, which specifies alternate paths taken based on some Boolean expression. As Figure 20-5 shows, you represent a branch as a diamond. A branch may have one incoming and two or more outgoing flows. On each outgoing flow, you place a Boolean expression, which is evaluated on entering the branch. The guards on the outgoing flows should not overlap (otherwise, the flow of control would be ambiguous), but they should cover all possibilities (otherwise, the flow of control would freeze).
Figure 20-5. Branching

Branches are a notational convenience, semantically equivalent to multiple transitions with guards, as discussed in Chapter 22 . |
Branching and iteration are possible in interaction diagrams, as discussed in Chapter 19 . |
Forking and Joining
Simple and branching sequential transitions are the most common paths you'll find in activity diagrams. Howeverespecially when you are modeling workflows of business processesyou might encounter flows that are concurrent. In the UML, you use a synchronization bar to specify the forking and joining of these parallel flows of control. A synchronization bar is rendered as a thick horizontal or vertical line.
A concurrent flow of control often lives in the context of an independent active object, which is typically modeled as either a process or a thread, as discussed in Chapter 23; nodes are discussed in Chapter 27 . |
Figure 20-6. Forking and Joining

Active objects are discussed in Chapter 23; signals are discussed in Chapter 21 . |
Swimlanes
You'll find it useful, especially when you are modeling workflows of business processes, to partition the activity states on an activity diagram into groups, each group representing the business organization responsible for those activities. In the UML, each group is called a swimlane because, visually, each group is divided from its neighbor by a vertical solid line, as shown in Figure 20-7. A swimlane specifies a set of activities that share some organizational property.
Figure 20-7. Swimlanes

A swimlane is a kind of package. Packages are discussed in Chapter 12; classes are discussed in Chapters 4 and 9; processes and threads are discussed in Chapter 23 . |
Object Flow
Objects may be involved in the flow of control associated with an activity diagram. For example, in the workflow of processing an order as in the previous figure, the vocabulary of your problem space will also include such classes as Order and Bill. Instances of these two classes will be produced by certain activities (Process order will create an Order object, for example); other activities may use or modify these objects (for example, Ship order will change the state of the Order object to filled).
Objects are discussed in Chapter 13; modeling the vocabulary of a system is discussed in Chapter 4 . |
Figure 20-8. Object Flow

Dependency relationships are discussed in Chapters 5 and 10 . |
The values and state of an object are discussed in Chapter 13; attributes are discussed in Chapters 4 and 9 . |
Expansion Regions
Often the same operation must be performed on the elements of a set. For example, if an order comprises a set of line items, the order handler must perform the same operation for each line item: check availability, look up the cost, check if this kind of item is taxable, and so on. Operations on lists are often modeled as loops, but then the modeler must iterate over the items, extract them one at a time, perform the operation, assemble the results into an output array, increment the index, and check for completion. The mechanics of executing the loop obscure the actual significance of the operation. This extremely common pattern can be modeled directly using an expansion region .An expansion region represents a activity model fragment that is performed on the elements of a list or set. It is shown in an activity diagram by drawing a dashed line around a region in the diagram. The inputs to the region and the outputs from the region are collections of values, such as the line items in an order. Collection inputs and outputs are shown as a row of small squares joined together (to suggest an array of values). When an array value arrives at a collection input on an expansion region from the rest of the activity model, it is broken apart into the individual values. The execution region is executed once for each element in the array. It is unnecessary to model the iteration; it is implicit in the expansion region. The different executions can be performed concurrently, if possible. When each execution of the expansion region completes, its output value (if any) is placed into an output array in the same order as the corresponding input. In other words, an expansion region performs a "forall" operation on the elements of an array to create a new array.In the simplest case, an expansion region has one array input and one array output, but it can have one or more input array and zero or more output arrays. All of the arrays must be the same size, but they need not contain the same type of value. Values from corresponding positions execute together to produce output values at the same position. The region could have zero outputs if all the operations are performed as side effects directly on array elements.Expansion regions allow operations on collections and operations on individual elements of the collections to be shown on the same diagram, without the need to show all of the detailed but straightforward iteration machinery.Figure 20-9 shows an example of an expansion region. In the main body of the diagram, an order is received. This produces a value of type Order, which consists of an array of LineItem values. The Order value is the input to an expansion region. Each execution of the expansion region works on one element from the Order collection. Therefore, inside the region the type of input value corresponds to one element of the Order array, namely a LineItem. The expansion region activity forks into two actions: one action finds the Product and adds it to the shipment, and the other action computes the cost of that item. It is not necessary that the LineItems be taken in order; the different executions of the expansion region can proceed concurrently. When all executions of the expansion region are complete, the Items are formed into a Shipment (a collection of Products) and the charges are formed into a Bill (a collection of Money values). The Shipment value is the input to the ShipOrder action and the Bill value is the input to the SendBill action.
Figure 20-9. Expansion region

Common Uses
You use activity diagrams to model the dynamic aspects of a system. These dynamic aspects may involve the activity of any kind of abstraction in any view of a system's architecture, including classes (which includes active classes), interfaces, components, and nodes.
The five views of an architecture are discussed in Chapter 2; classes are discussed in Chapters 4 and 9; active classes are discussed in Chapter 23; interfaces are discussed in Chapter 11; operations are discussed in Chapters 4 and 9; use cases and actors are discussed in Chapter 17; components are discussed in Chapter 15; nodes are discussed in Chapter 27; systems and subsystems are discussed in Chapter 32 . |