Activity Diagrams

Activity vs. Statechart Diagrams

Statechart diagrams can be used to represent lifecycles, protocols, use cases, and workflows.

UML activity diagrams are statechart diagrams with a few extra features that are especially useful for modeling workflows.

States and Transitions

An activity diagram represents a procedure, workflow, process, or activity.

The nodes of an activity diagram always represent actions, and an arrows represents a transition from the source activity to the target activity that is triggered by the completion of the source activity. For example:

(Recall that a transition without a trigger is assumed to be triggered by a completion event.)

A composite action can be thought of as a subprocedure or subactivity:

We can represent sub-procedures using activity diagrams:

We can include the name of the sub-procedure activity diagram in a composite activity:

Decisions

Decision nodes are represented by diamonds with two targets. The transitions to the targets are labeled by mutually-exclusive Boolean-valued guard conditions (in braces).

Initial and Final Activities

An activity diagram has one initial activity (the target of a transition emanating from a solid circle node,) and zero or more final activities (the sources of transitions terminating in a solid circle surrounded by an empty circle):

Synchronization

We can use forks to indicate that either multiple activities can be done in parallel or that the order doesn't matter. We can use joins to indicate that several activities must be completed before the next activity begins:

Object Flows

An object can be passed from one action to the next:

In this example, when the validate form action is completed, an instance of the Form class in state = validated is passed to the process form action.

An object-in-state can be passed from one action to the next. In each case it's the same object, only the state changes:

Swimlanes

Actions are performed by an actor. Different actions in the same activity might be performed by different actors. We can show which action is performed by which actor by introducing swimlanes for each actor. The actions performed by an actor are in that actor's swimlanes.

Examples

Describing an algorithm

// converts Farhenheit to centigrade
void temperatureConverter() {
   do {
      Temperature fDegrees = enterTemperature();
      if (invalid(fDegrees)) {
         reportError();
         break;
      }
      Temperature cDegrees = 5 * (fDegrees - 32)/9;
      display(cDegrees);
   } while(true);
   display("bye");
}

tempConverter

Describing a workflow (Job Processing Systems)

workflow1

Another Workflow

Specifying a Use Case

Specifying a Protocol

rfp

Modeling Protocols: The Contract Net Protocol

rfp2