Modeling with UML Activity Diagrams

Technote (FAQ)

Question

Modeling with UML Activity Diagrams

Answer

The UML Activity diagram is a multi-purpose flow diagram that enables you to model business workflow, as well as algorithmic workflow of an implementation class or method. An Activity Diagram is similar to a flow chart, except that it provides the additional ability to model concurrent flows.

This week we'll take a look at how to use UML Activity Diagrams both to model the workflow of a business process, or Use Case, and the algorithm of an implementation method.

Using an Activity Diagram to Model the Flow of Use Cases

If you are familiar with the Unified Modeling Language (UML), you know that you can use Use Cases to model high-level business processes, and lower-level system processes. However, while the Use Case enables you to capture scenarios and the descriptions of each, it does not enable you to model workflow. Generally, a UML Sequence diagram is used to model workflow details, in terms of objects and the chronological passing of messages between objects. This is where the UML Activity diagram comes in – as an alternate to the Sequence diagram, enabling you to model the workflow of the business or system scenario.

Using an Activity Diagram to Model Flow of Classes

In addition, the behavior of a class is modeled with a State diagram – you model the states that the class can be in, and events that trigger transitions from state to state. In this regard, a UML Activity diagram is considered an extension to the State diagram.

Using an Activity Diagram to Model Flow of Methods

Finally, you may also use activity diagrams to model the algorithms of an operation. In general, if an operation is fairly simple, the behavior of the method is modeled directly with code. If an operation is algorithmically complex, you may choose to model it graphically with an Activity diagram.

Working in Different Domains Without Name Clashes

One of the problems with using Activity diagrams to model such different concepts -- high-level business concepts with the Use Case, and intricate implementation details for the method – is name collisions. For example, an activity such as Get Credit Card Number may mean a completely different thing in the context of an Activity model for a business Use Case Process Order , versus the Activity Model for a method Process_Order . In the first instance, you may be modeling that the activity involves a web form asking the customer for his/her credit card. For an implementation method, Get Credit Card Number may involve a Process Order class requesting information from a Customer class.

To establish the domain that you are working in, you assign the UML Activity diagram that you are working with to a Model . Within the Model properties, you specify what domain (Use Case, Class, or Method) you are modeling. In the Activity diagram, all action states and other modeling elements that are used become 'keyed' to this model, therefore enabling you to use the same name of an action state to mean two different things, depending on its domain.

Example:

Let's use an Activity diagram to model the workflow of a process Make Reservation . Within the course of this activity diagram, we use the action state Get Credit Card Number as a high-level business process, performed by the Reception organizational unit of our business (this could be a physical person or a web form asking the customer for his/her credit card number).

To model an Activity diagram for a Use Case, we would do the following:

1. Right-mouse click on Diagrams in the Browser and select UML Activity diagram.

2. Give the Activity Diagram a name, and click OK . You will automatically be prompted to name a model that the diagram reports to.

3. Type in the name of the model in the model name dialog. Once the name is entered, click on the Define button to define it.

4. In the Activity Model dialog, type in the name of the Use Case that this diagram will represent. You may click on Choices to get a list of preexisting Use Cases.

Below is an example of an Activity diagram created for the business process Make Reservation .

Now let's say you wanted to model the algorithm of a method. You could again use a UML Activity diagram to do so.

1. Right-mouse click on Diagrams in the Browser and select UML Activity diagram.

2. Give the Activity Diagram a name, and click OK . You will automatically be prompted to name a model that the diagram reports to.

3. Type in the name of the model in the model name dialog. Once the name is entered, click on the Define button to define it.

4. In the Activity Model dialog, type in the name of the Method that this diagram will represent, and the method's class. You may click on Choices to get a list of preexisting methods and classes.

Now you can model the algorithm of the method. Note that you can use the action state Get Credit Card Number in this diagram, and since it is 'keyed' to a different model than the first time you used it (in the previous diagram), it is completely independent and can represent different information.

That's this week's tip. For more information on UML, please see the on-line help