UML: Activity Diagrams
Published By: Scott Stroz on Mar 27, 2005 at 12:29 PM
Times Viewed: 22130
Categories: None
In my last major entry on the UML I covered the Use Case diagram. The Use Case diagram is a diagram used to gather requirements and help with analysis. Once you have gathered your Use Case diagrams you can continue on with the analysis phase by using Activity Diagrams.
Activity Diagrams are used to illustrate the activities implicit in a use case. For example, consider this Use Case diagram:
This Use Case diagram clearly states that Search Users will Search Content. However, it doesn't make any attempt to say anything about the steps involved. This is where Activity Diagrams come in.
Activity Diagrams are very similar to standard flow charts. The major difference is that activity diagrams allow for parallel processing of tasks. (In the ColdFusion world you really don't need to worry about this difference.)
Here is an example Activity Diagram illustrating the Get Out of Bed use case:
This diagram is made up of the following notational elements:
Activities
Activities are used to indicate actions which are preformed in your diagram. In the previous example the activities were: Alarm Goes Off, Hit Snooze, Shut off Alarm and Get Out of Bed. Activities are shaped like pills and have a description inside.
Transitions
The lines with open arrow heads are called Transitions. Transitions are used to indicate the process flow between elements in your diagram. In the Get Out of Bed example above, you can see that the Alarm Goes Off activity transitions to the Sleepy state. There are nine transoms total in the example.
Decision Points
There are two ways to draw logical branching in activity diagrams. The Get Out of Bed example uses a decision point "Still Tired?" If Still Tired? is Yes then the flow transitions to the Hit Snooze activity and then back to the Asleep state. If Still Tired? is No then the flow transitions on to the Shut off Alarm and Get Out of Bed activities.
The text shown in square brackets on transitions out of the decision points is called Guards. For flow to progress through a guarded transition the guard must evaluate to true in the context of the decision point. For example:
This rather simplified diagram illustrates the decisions involved in buying a car. We can see that if we've got less than a $100 we're going to be stuck in a used Yugo. However, as long as we don't have too much money we're going to be able to drive a Sensible Car. And, if we happen to have too much money we're going to end up with a nice sports car.
Guards need to be mutually exclusive. For instance, it wouldn't make since in the diagram above to show that if we have more than $100 that we'll buy a sensible car, because that could overlap with Too Much Money guard and we wouldn't know what to do.
You don't need to use decision points to show decisions. You can also simply draw multiple guarded transitions out of an activity. Here's the car buying diagram again, this time without the transition point:
In general, the decision to use Decision Points is up to you. (Frankly, no one seems to use the same conventions in UML diagrams anyhow, so you could probably use pink elephants to indicate decision points, so long as you're consistent!)
States
States are represented by rounded rectangles. (Sometimes they are segmented like in the examples above, sometimes they're not. As far as I can tell, there's no difference.) States are used to indicate milestones in processing of your activity diagrams.
In the example above there are three states, Asleep, Sleepy and Awake. These indicate the "state" of the person being woken up.
Starting State
Start States are a special type of state indicating the starting point for your activity diagram. There can be only one start state on your diagram. Starting States are always drawn as a filled circle. Sometimes people draw a descriptive caption underneath the Starting State. In the Get Out of Bed example we could probably have gotten rid of the Asleep state and called the starting state Asleep instead.
Ending State
Ending States are similar to Starting States; accept that they indicate ending points for processing. The other big difference is that there can be multiple Ending States on your diagram. Ending States are drawn as a filled circle with a ring around it. (It makes me think of Saturn, for some reason.) As with Starting States, sometimes people draw a descriptive caption underneath the Ending State. In the Get Out of Bed example we could probably have gotten rid of the Awake state at the end and called the Ending State Awake instead.
Forks and Joins
Seeing as my audience is primarily ColdFusion programmers, forks and joins probably won't make much of a difference to you (unless you use ColdFusion MX 7 Enterprise, which now has an asynchronous event gateway). However, for the sake of completeness I will do a brief overview of them.
Forks and Joins are shown as black bars and are used to indicate parallel processing. For an example, look at this diagram:

This diagram illustrates the process of getting in the shower. The diagram
starts with the Turn on Shower event. However, the shower always comes on cold
and takes a while to warm up, so, for the sake of efficiency, we will fork out
and do more than one thing at a time. In our example, while we Brush our Teeth
and Shave we are also busily waiting for the water to get warm and happily
wasting precious natural resources. When we're done with all of that, we will
join our processes back together and Get in Shower and proceed to play with the
Rubber Ducky.
Forks are always shown as a solid bar with one entry transition and multiple exit transitions.
Joins are always shown as a solid bar with multiple entry transitions and a single exit transition.
Swim Lanes
There is one other big notational element to activity diagrams, Swim Lanes. Swim Lanes are used to illustrate which portions of a system are responsible for particular elements of your diagram. Here's an example:
This diagram illustrates a User and a Website. The user is attempting to log on to the website. As you can see, the User is responsible for providing login credentials, while the Website is responsible for authenticating the user.
One thing about swim lanes which confuses me is where elements like Show Error Message or Show Intranet should be placed. I put them in the User column because the User sees it. However, it's really the website which performs the action of showing, isn't it? My opinion is that it doesn't really matter where these are placed. The purpose is to show that the User and the Website work together to Authenticate the User and Show the Intranet.
Note: The diagram above is interesting too because it shows multiple Ending States, one for success and one for failure.
How to Draw Activity Diagrams
The process for creating activity diagrams is pretty simple. You can accomplish it by following these steps:
- Identify a Use Case you want to create an Activity Diagram for.
- Draw a simple Activity Diagram which shows the primary success scenario from beginning to end. Don't worry too much about details yet.
- Go back and add in alternative paths through the use case, including those which will result in errors.
- Add detail to the diagram.
As a note, you might end up with portions of your diagram which are so complex that they warrant an activity diagram. This is part of the point of these diagrams. This level of discovery helps you understand the scope of your software.
Let's Draw Some Diagrams
In previous entries on UML, I created a requirements document and Use Case diagrams for a searching and indexing API for ColdFusion based on Lucene. I will now use the Use Case Diagrams to create a set of Activity Diagrams.
Search Content
The Search Content Use Case diagram was pretty simple:
I started diagramming by creating a simple Activity diagram which illustrated the primary success scenario.
Now that I have the primary success scenario I need to go back and add some detail. For instance, what happens if I don't provide any criteria or what happens if the index I'm searching doesn't exist?
Now that I've got a pretty good idea of the flow through the process, I would like to get a better idea of what we're interacting with. I know I've got a Search User and a Search API. I think we could add some swim lanes to help clear this up a bit.
Index Content
The Index Content Use Case will necessitate a bit more complexity in our next Activity Diagram. Here's the Use Case diagram:
I started by modeling the primary success scenario like this:
This activity diagram does a pretty good job of illustrating the primary success scenario but it does need some more detail. For instance, what happens when the index does not exist? How does the system know where the index is located? What if there are no items in the queue? What if you can't retrieve the document?
I went ahead and added some detail and some swim lanes to this diagram and this is what I came up with:
By now, you should be able to read this diagram (and I'm tired of typing) so I'll leave its interpretation to you.
One thing I've decided not to cover in this diagram is exactly what information is being indexed and how the information is being extracted from the document. This could easily warrant another activity diagram. However, I have some complex plans for these so I think I'll leave the implementation details to another type diagram, perhaps a sequence diagram.
Do you have any comments, criticisms or questions on this entry? If so, please leave feel free to comment below.











Nice examples! (Well, you complained that I didn't comment on your other UML stuff)
Posted By: Sean Corfield on Mar 27, 2005
I'll have everyone know I didn't complain. I meerly asked if he had read them and, if so, if he had any criticisms! After all, he is Mr. UML.
Besides, I can't get anyone else to comment!
Posted By: Doug Hughes on Mar 27, 2005
No comment.
Posted By: Boyzoid on Mar 27, 2005
Just wanted to thank you for posting these UML articles. I've recommended our junior developers to read these too.
Also, please check your UML category articles, there are two articles in UML category that don't belong there. If you can remove those from that category.
Posted By: Erki Esken on Mar 28, 2005
Erki,
You're welcome! It's been a lot harder to write these than I anticipated, but it's been well worth the effort. UML is an interesting tool.
The only advice I can give your junior programmers is to not get too wrapped up in the "correct" way to use UML. I havn't found any consistancy in how they're applied (or even in the notation!!) in any of the books I've read. Just try to be consistent in how you express your ideas.
If you (or anyone) have any feedback, questions, criticisms or anything else, please feel free to let me know.
Thanks for the encouragement.
Posted By: Doug Hughes on Mar 29, 2005
Doug,
I am trying to use a UML tool to map out a large coldfusion application for myself and 4 other developers who are working on the project. I have seen a few, but they all seem a little difficult to use. Which tool would you recommend for a CF developer?
Posted By: Jeff on May 12, 2006
Do you know any tool (c++ or java) to graphically represent acitivty diagrams thanks to a provided API ?
Posted By: Remi on Jun 29, 2006
do u have the activity diagram about manufacturing car?thanks
Posted By: ying on Aug 27, 2006
Your comment about consistent modelling is quite interesting. I have watched UML and other software modelling paradigms for many years and UML has always seemed "loose" in IMHO. My expertise is in IDEF0/SADT modelling - something small in symbol set, but very rigid in style. I'm not interested in the "code from drawings" goal, but there has to be some rules that force you, for example, to create a class diagram for objects you depict in other diagrams. It would be nice to see documentation about relationships between UML elements in diferent diagrams.
Posted By: Lou Arnold on Sep 14, 2006
this was a one shot good explanation about activity diagrams, I enjoyed reading this and it helped me at the most. thank you Doug Hughes
Posted By: Priya on Sep 18, 2006
Wow Wow Wow! The best set of examples and awesome explanation and walk through.
This is the best article I have read on Activity diagrams.
Posted By: Sridhar Visvanath on Mar 6, 2007
Awesome. This is the kind of explaination, i was looking for better understanding of activity diagram.
Posted By: Kannan on Mar 14, 2007
Good article!
I have noticed some Use Cases are in your Activity Diagram, for instance, "Delete from index". After all, what are the differences between a Use Case and an Activity? My answer is the low level use cases are same as activities.
What would you think?
Thanks a lot.
Haibo Hu
Posted By: Haibo Hu on Mar 22, 2007
Hi,
Nice and Helpful Article.
I am more interested in Swim Lane diagram. Could you please let me know hoe to draw these diagrams i mean..using which tool?
It would be very useful for me if you could provide me the details related to swim lane diagrams like
1) what is swim lane diagram
2) its usage
3) Tools to draw the diagram.
Thanks
Yogesh
Posted By: Yogesh Puranik on Apr 5, 2007
Finally some serious examples. Was tired of browsing web. Excellent work ! Put more if you find something interesting real-life examples. Although, I liked also waking up example to show core. Really good !!!
Posted By: Petar on Jul 21, 2007
sfasdf
Posted By: asdfarere on Oct 26, 2007
asdfasdf
Posted By: asdfarere on Oct 26, 2007
Hi to all. I need sequence diagram for shopping cart (search, add product, update and delete product, cart, purchase)
Posted By: Ashok on Oct 26, 2007
It’s a Very good Article covering most of the aspects with good example which otherwise make designer life difficult.
- Trib
Sr. Architect.
KPIT /DFS.
Posted By: Tribhuwan Bisht on Nov 15, 2007
does any body told me
" DOES ACTICITY DIAGRAM SUPPORT USE CAE IF YES HOW?"
plz i need urgently
Posted By: sania on Nov 20, 2007
I need to throw exception: create an exception object and throw it.
Of course that has to be done in the sequence diagram.
I don't know how to model this, can you help with this....
P.
Posted By: Petar on Nov 21, 2007
Hi to all. I need sequence diagram for shopping cart (search, add product, update and delete product, cart, purchase)
Posted By: Naozup on Nov 26, 2007
does any body told me
" DOES ACTICITY DIAGRAM SUPPORT USE CAE IF YES HOW?"
Well, you should create a collaboration diagram where you link use case with sequence diagrams. This way you do the traceability.
Perhaps there are other solutions as well, such as put them in the same package, etc.
Posted By: Petar on Nov 26, 2007
Nice and helpful diagrams. iam interesred to learn more from this site. kindly help me to learn more.Daisy
Posted By: Daisy on Jan 28, 2008
it extremely useful diagrams.let me know more.
Posted By: Daisy on Jan 28, 2008
Not Good information which can be use for .............
Posted By: bhumika on Feb 21, 2008
Thnaks for the help.A good tool is Visual Paradigm for UML..
Posted By: mark on Mar 19, 2008
thanks
Posted By: bhavesh on Apr 8, 2008
Hi Master.
Please Send ME A Simple Project In Unified Moddeling Language
Thank's
I need a Beauty Project
I have Not Enough Time
Posted By: CSHarp on May 3, 2008
plse help me in drawing dioagrams of search engine.
Posted By: vini on May 24, 2008
i need stock maintenance system use case diagram
Posted By: praveen on Jul 22, 2008
please help me in use case diagram for library maintenance system
Posted By: praveen on Jul 22, 2008
This is a good arcticle on how to use class and activity diagram.
Posted By: Schma on Jul 30, 2008