Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

Object Oriented Programming

1
Today’s Topics
• Activity Diagrams
• Activity States & Action States
• Branching
• Forking & Joining
• Swimlanes
• Uses of Activity Diagrams

2
Activity Diagrams
• Similar to the Flowcharts that you are used
to. It shows steps (called activities) as well
as decision points and branches

• Activity:
– An ongoing non-atomic execution within a
state machine

3
Activity Diagrams
• Activity diagrams are used to model the
dynamic aspects of a system.
• May involve any kind of abstraction in any
view of a system’s architecture including
classes, interfaces, components and nodes
• Can be attached to use cases (to model a
scenario) and to collaborations (to model
the dynamic aspects of a society of objects)

4
Activity Diagrams
• Interaction diagrams (sequence diagrams
and collaboration diagrams) are also aimed
at modeling the dynamic aspects of a
system, but they concentrate on the objects
that interact by passing messages.
• Activity diagrams focus on the activities
(that take place among objects) themselves.

5
Activity Diagrams
• Activity diagrams are mainly used in two
ways
– To model a workflow (focus on activities as
viewed by the actors that collaborate with the
system)
– To model an operation (used as flowcharts to
model the details of a computation)

6
Activity Diagrams
• An activity diagrams shows the flow from
activity to activity.
• Activity:
– An ongoing non-atomic execution within a
state machine
• An activity diagram has activity states and
action states

7
Activity States & Action States
• Action States
– Executable Atomic Computations
• Evaluate expression, send a signal to an object
• Activity States
– Can be further decomposed
– Can be interrupted ( non atomic )
• An action state is an activity state that
cannot be further decomposed

8
Traditional Flow Activity Diagram
Chart
start

read x
read x

x=0 true [x = 0]

false [else]
x ++
x ++;

stop
9
Activity States & Action States
• UML does not specify the language to be
used in activity states and action states; It
can be
– Structured text
– Syntax and semantics of a specific
programming language

10
Transitions
• Used to specify the flow from one activity
state (or action state) to another activity
state (or action state)
• Graphically represented as arrows
• After the completion of one activity state
(or action state), the flow of control passes
immediately to the next activity state

11
Activity Diagrams and State Diagrams

• An activity diagram is a special case of a


state diagram in which all or most of the
states are activity states.
• An activity diagram may also contain
objects.

12
Branching

• Specifies alternate paths taken based on a


Boolean expression
• Represented as a diamond
• May have one incoming path and two or
more outgoing paths

13
Branching: Example

14
Forking and Joining
• Represent Parallel flows

• Use Synchronization bar


to fork and join these
parallel flows

• Joins and forks should


balance
15
Swimlanes
• Partition the activity states in a diagram into
groups

• Each swimlane has a unique name within its


diagram

• Represents a real world entity

16
Swimlanes
• Each swimlane represents a high level
responsibility for part of the overall activity
of an activity diagram
• Each swimlane may be implemented by one
or more classes
• Each activity should belong to exactly one
swimlane but transitions may cross
swimlanes

17
Swimlanes:
Example

18
Activity diagrams & Workflows
• Workflows represent business processes
where automated and human processes
interact with the system
• Can be represented by activity diagrams

19
Representing a workflow using an
activity diagram
• Establish a focus for a workflow
• Identify important business objects that
have high level responsibilities in the
workflow and create swimlanes for them
• Identify the pre-conditions of the initial
state and post-conditions of the final state
• Specify activity states and action states

20
Representing a workflow using an
activity diagram
• Collapse actions states in to activity states
when necessary and provide separate
activity diagrams
• Use branching and forking/joining when
necessary
• Represent object flows when necessary

21
Representing a workflow using an
activity diagram
• Example: Customer returns in a retail
business (pages 269-270)

22
Activity Diagrams and Operations
• An activity diagram can be used to model
the flowchart of an operation
• The resultant activity diagram is attached to
the operation in concern and to the
underlying model

23
Representing an Operation using
an Activity Diagram
• Collect the abstractions that are involved with
the operation such as its parameters, return
type and the attributes of the enclosing classes
• Identify the pre-conditions of the initial state
and the post-conditions of the final state
• Specify activity states and action states
• Use branching and forking/joining when
necessary
24
Representing an Operation using
an Activity Diagram
• Example: operation intersection of the Line
class that takes a Line object as a parameter
and returns a Point object (pages 271-272)
• Using activity diagrams to represent a
flowchart of an operation almost makes
UML a visual programming language
• Should be used only when operations are
complex and difficult to comprehend

25
Forward Engineering and Reverse Engineering

• Forward engineering the activity diagram in


to code is possible, especially in
representing operations
• Reverse engineering the activity diagrams
from the code is possible, especially in
representing operations

26
Reference
• The Unified Modeling Language User
Guide
• Grady Booch, James Rumbaugh, Ivar Jacobson
– Chapter 19

27

You might also like