Activity Diagrams

Activity diagrams subsume data flow diagrams, flowcharts, and Petri-nets.

Activity diagrams are related to statechart diagrams (finite state machines, in particular Meely and Moore machines).

We can use an activity diagram to model the process/activity executed by a system (organization, hardware, software, etc.), use case (function), component (object), protocol, etc. This is called the context of the activity.

An activity is a function with an associated context (resources) and actor (processor, agent). The actor performs or executes the activity. The activity may have an input, it may process that input, and it may produce an output.

An activity diagram is a directed graph. There are several types of nodes:

Actions
Data
   Objects
   Parameters
Control
   Start
   Final
      End Activity
      End Flow
   Branch/Merge
   Fork/Join

Tokens representing data/information, resources/objects, and/or control flow from node to node following paths indicated by the arrows connecting the nodes.

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");
}



Describing a workflow (Job Processing Systems)

Another Workflow

Specifying a Use Case

Specifying a Protocol

An Implementation

abstract class Activity {
   Actor processor;
   abstract Object execute(Object input, Classifier context);
}

abstract class Branch extends Activity {
   Activity concequence, alternative;
   abstract boolean condition(Object input, Classifier context);
   Object execute(Object input, Classifier context) {
      if (condition(input, context)) {
         return consequence.execute(input, context);
      } else {
         return alternative.execute(input, context);
      }
   }
}

class ActivityDiagram {
   List<Activity> activities;
   Object execute(Object input, Classifier context) {
      // execute each activity
   }
}