You are on page 1of 20

UML Activity Diagrams

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


1
Objectives

 To read and write UML activity diagrams


 To know when and how to use activity
diagrams

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


2
Topics

 Processes and process descriptions


 Activity diagram notation
 Activity diagram execution model
 Making activity diagrams

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


3
Processes and Their Description

AA process
process isis aa collection
collection ofof related
related tasks
tasks that
that
transforms
transforms aa set
set ofof inputs
inputs into
into aa set
set of
of outputs.
outputs.

Process description notations describe


design processes as well as computational
processes we design.

An
An activity
activity diagram
diagram shows
shows actions
actions and
and the
the
flow
flow of
of control
control and
and data
data between
between them.
them.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


4
Activities and Actions

An
An activity
activity isis aa non-atomic
non-atomic task
task or
or
procedure
procedure decomposable
decomposable intointo actions.
actions.

An
An action
action isis aa task
task or
or procedure
procedure that
that
cannot
cannot be
be broken
broken into
into parts.
parts.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


5
Activity Graph Elements

Do Laundry
initial node
Sort
Clothes action node
Wash Wash
Whites Darks
activity symbol
Dry
Clothes

activity edge
Fold
Clothes

activity final node

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


6
Execution Model
 Execution is modeled by tokens that are produced
by action nodes, travel over action edges, and are
consumed by action nodes.
 When there is a token on every incoming edge of
an action node, it consumes them and begins
execution.
 When an action node completes execution, it
produces tokens on each of its outgoing edges.
 An initial node produces a token on each outgoing
edge when an activity begins.
 An activity final node consumes a token available
on any incoming edge and terminates the activity.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


7
Branching Nodes

Dry Clothes

merge
node Run Drier

[still wet]

decision [else] guards


node Fold
Clothes

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


8
Branching Execution

 If a token is made available on the incoming


edge of a decision node, the token is made
available on the outgoing edge whose guard
is true.
 If a token is available on any incoming edge
of a merge node, it is made available on its
outgoing edge.
 Guards must be mutually exclusive.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


9
Deadlock

RunDrier cannot
Try to Dry
Clothes execute: when the
Run Drier activity begins,
there is a token on
[still wet]

[else]
the edge from the
Fold initial node but not
Clothes
on the other
incoming edge.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


10
Forking and Joining Nodes

Do Laundry

Sort
Clothes fork node

Wash Wash
Whites Darks

Dry
Clothes join node
Fold
Clothes

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


11
Forking and Joining Execution

 A token available on the incoming edge of


a fork node is reproduced and made
available on all its outgoing edges.
 When tokens are available on every
incoming edge of a join node, a token is
made available on its outgoing edge.
 Concurrency can be modeled without these
nodes.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


12
Object Nodes

Data and objects are shown as object nodes.

Battleship
Cruiser
[damaged]

Battlegroup
Destroyer object
[captured] node
state

object node

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


13
Control and Data Flows

 Control tokens do not contain data, data


tokens do.
 A control flow is an activity edge that is a
conduit for control tokens.
 A data flow is an activity edge that is a
conduit for data tokens.
 Rules for token flow through nodes apply to
both control and data tokens, except that
data is extracted from consumed tokens and
added to produced tokens.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


14
Control and Data Flow Example
Wash and Dry
Clothes
control flow
Wash
Clothes

Clothes
[wet]

data flows
Run Drier

Clothes

[still wet]

[else]

Fold
Clothes

control flow

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


15
Activity Parameters

 Activity parameters are object nodes placed


on activity symbol boundaries to indicate data
or object inputs or outputs.
 Activity parameters contain the data or object
name.
 Activity parameter types are specified in the
activity symbol beneath the activity name.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


16
Activity Parameter Example

activity FindMax
parameter a : int[1..*]
max : int

types a
max = a[0]
i=1

input
activity [else]

parameter [i < a.length]


[else]

[max < a.[i]]

max = a[i] max

output
activity
i++
parameter

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


17
Activity Diagram Heuristics

 Flow control and objects down the page and


left to right.
 Name activities and actions with verb phrases.
 Name object nodes with noun phrases.
 Don’t use both control and data flows when a
data flow alone can do the job.
 Make sure that all nodes entering an action
node can provide tokens concurrently.
 Use the [else] guard at every branch.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


18
When to Use Activity Diagrams

When making a dynamic model of any process.


• Design processes (what designers do)
• Designed processes (what designers create)
 During analysis
 During resolution

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


19
Summary
 A process is a collection of related tasks that
transforms a set of inputs to a set of outputs.
 UML activity diagrams model processes by depicting
actions and the flow of control and data between
them.
 Activity symbols contain activity graphs consisting of
• action nodes
• action edges
• data nodes
• special nodes for starting and stopping activities, branching,
forking, and joining
 Activity diagrams can represent any process and are
useful throughout software design.

© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


20

You might also like