Uml Basics
Uml Basics
Uml Basics
jsp
UML basics
by Donald Bell
IBM Global Services
The notation
The activity diagram's notation is very similar to that of a statechart
diagram. In fact, according to the UML specification, an activity diagram is
a variation of a statechart diagram1. So if you are already familiar with
statechart diagrams, you will have a leg up on understanding the activity
diagram's notation, and much of the discussion below will be review for
you.
The basics
First, let's consider the action element in an activity diagram, whose
official UML name is action state. In my experience, people rarely if ever
call it an action state; usually they call it either action or activity. In this
article, I will always refer to it as action and will use the term activity only
to refer to the whole task being modeled by the activity diagram. This
distinction will make my explanations easier to understand.
The activity's flow terminates when the transition line of the last action in
the sequence connects to a "final state" symbol, which is a bullseye (a
circle surrounding a smaller solid circle). As shown in Figure 4, the action
"Ticket Rep Mails Tickets" is connected to a final state symbol, indicating
that the activity's action sequence has reached its end. Every activity
diagram should have at least one final state symbol; otherwise, readers
will be unclear about where the action sequence ends, or perhaps assume
that the activity diagram is still a work in progress.
Decision points
The UML specification provides two ways to model decisions like this.
The first way is to show a single transition line coming out of an action and
connecting to a decision point. The UML specification name for a decision
point is decision, and it is drawn as a diamond on an activity diagram.
Since a decision will have at least two different outcomes, the decision
symbol will have multiple transition lines connecting to different actions.
Figure 5 shows a fragment of a sample activity diagram with a decision.
Figure 5: A decision point models a choice that must be made
within the sequence of actions.2
Merge points
Sometimes the procedural flow from one decision path may connect back
to another decision path, as shown in Figure 6 at the "Customer's Age > =
21" condition. In these cases, we connect two or more action paths
together using the same diamond icon with multiple paths pointing to it,
but with only one transition line coming out of it. This does not indicate a
decision point, but rather a merge.
Figure 6 shows the same decision as in Figure 5, but Figure 6 expands the
activity diagram. Performing a check of the customer's age leads the user
to a second decision: If the customer is younger than 21, the bartender
must tell the customer to order another non-alcoholic drink, which takes
our sequence back to the action "Customer Orders Drink." However, if the
customer is 21 years old or older, then our action sequence takes take us
to the same action the bartender would follow if the person had ordered a
non-alcoholic drink: "Get Drink For Customer."
Figure 6: A partial activity diagram, showing two decision points
("Drink is alcoholic" and "Customer's age < 21") and one merge
("else" and "Customer's age >= 21")
Click to enlarge
An alternative approach
If you choose this second approach, you must have multiple action
sequences merge into a single sequence. To do this, you connect the last
transition lines in the specific sequence to the action at which the
sequence becomes one again. In Figure 8, this is illustrated with the
transition line from "Tell customer to order a non-alcoholic drink" returning
to the action "Customer orders drink."
When modeling activities, you sometimes need to show that certain action
sequences can be done in parallel, or asynchronously. A special notation
element allows you to show parallel action sequences, or synch states, as
they are officially named, since they indicate the synchronization status of
the flow of activity. Synch states allow the forking and joining of execution
threads. To be clear, a synch state that forks actions into two or more
threads represents a de-synchronizing of the flow (asynchronous actions),
and a synch state that joins actions back together represents a return to
synchronized flow. A synch state is drawn as a thick, solid line with
transition lines coming into it from the left (usually) and out of it on the
right (usually). To draw a synch state that forks the action sequence into
mulitple threads, first connect a transition line from the action preceding
the parallel sequence to the synch state. Then draw two transition lines
coming out of the synch state, each connecting to its own action. Figure 9
is an activity diagram fragment that shows the forking of execution
modeled.
Figure 9: A thick, solid line indicates a synch state, allowing two or
more action sequences to proceed in parallel.
When you fork execution into multiple threads, typically you have to rejoin
them at some point for later processing.3 Therefore, the synch state
element is also used to denote multiple threads joining back together into
a single thread. Figure 10 shows an activity diagram fragment that has
two threads joining into one.
In Figure 10, the "Verify Ordered Products Are In Stock" and the "Verify
Customer Has Available Credit" actions shown in Figure 9 have completed
processing,4 and the "Accept Order" action is processed. Note that the
single transition line coming out of the synch state means there is now
only one thread of execution.
In all the above examples the synch states are drawn as thick vertical
lines; however, the UML specification does not require these lines to be
oriented in one way or another. A synch state can be a horizontal thick
line or even a diagonal thick line. However, UML diagrams are meant to
communicate information as easily as possible; so a person should
typically draw a synch state icon as a vertical or horizontal line; only when
it makes complete sense (e.g., when running out of space on a whiteboard
or piece of paper) should a synch state be drawn at an odd angle.
Swimlanes
Object flow
Note that in Figure 13, instead of transition lines between the two
activities, we see action-object flow relationship symbols. This is because
an action-object flow relationship between two actions implies transition to
the other action, so transition lines are considered redundant.
Object in state
The object in state symbol is the rectangle in Figure 13. The first part of
the object in state symbol is the underlined text. The underlined text in
the rectangle is the object's class name -- in our example "Order" -- and
this class would be found on one of the modeled system's class diagrams.5
The second part of the object in state is the text inside the brackets, which
is the object's state name. Including the object's state is optional, but I
recommend you do so if an action modifies the object's state.6 Figure 14
shows a complete activity diagram with multiple action-object flow
relationships.
Figure 14: The "Place Order" action puts the Order object into the
"Placed" state; then the "Verify Ordered Products Are In Stock"
action moves the Order object into the "Accepted" state.
Click to enlarge
The inclusion of action-object flow relationships does not change the way
you read an activity diagram; it just provides additional information. In
Figure 14, the "Place Order" action puts the Order object into the "Placed"
state; later, the "Verify Ordered Products Are In Stock" action moves the
Order object into the "Accepted" state. We know that these actions are
modifying the Order's states, because the objects in state symbols have
the states on them.
Subactivity state
The subactivity state represents another activity diagram that you can use
when you want to nest another activity in the flow of an activity. A
subactivity state is placed where an action state on an activity diagram
would be located. You also draw a subactivity state in the same way as an
action state, with the addition of an icon in the lower right corner depicting
a nested activity diagram. The name of the subactivity is placed in the
symbol, as shown in Figures 15 and 16.
Note the slight difference between the subactivity state icons placed in the
lower right corners in Figures 15 and 16. The UML 1.4 specification does
not explicitly state what the icon should be, but instead says this:
For now, this means that there is not a standard symbol, since subactivity
state icons can be different depending on who (or what tool) adds them to
the activity diagram. So until firmer agreement is reached on the
appearance of this icon, it is best to simply be consistent: Use the same
icon every time you represent a subactivity state.
Conclusion
Like all UML diagrams, the number one purpose of the activity diagram is
to communicate information effectively. One main reason to include
activity diagrams in an overall system model is that they model the
procedural flow of control for various activities. This is important, because
this sort of model allows business people to get a better understanding of
the business environment in which a system will run. Of course, activity
diagrams are not limited to modeling business processes; they can also be
used to model computer processes.
Typically, you will not use every notation element described in this article
when you create your own activity diagrams. But you will make frequent
use of the initial state, transition line, action state, and final state notation
elements.
Notes
1 In the current draft version of UML 2.0, the activity diagram will no longer inherit from the
statechart diagram. However, a full discussion of this subject is outside the scope of this
article..
2In the United States, people younger than 21 years of age cannot purchase alcoholic
beverages, such as beer or wine.
3 In activity diagrams, if you fork execution into multiple threads there is no requirement to
rejoin the threads -- it's possible, though unlikely, to have an activity sequence that breaks
off and then just terminates. An example of an activity sequence that might fork off and need
not be synchronized back would be a process for notifying an external system or third party
of an event.
4 Remember that one action might take longer to execute than the other.
5 Although the text implies that every class in a UML model must appear in a class diagram,
this is not required by the UML specification. It is completely possible that a class could
appear on an activity diagram, but not on any class diagram.
6 Just as the class Order is modeled on one of the system's class diagrams, the state should
also be modeled on a statechart diagram.