You are on page 1of 79

Behavioral Modeling with UML 2.

PowerPoint Presentation derived from Dennis, Wixom & Tegarden


Systems Analysis and Design
John Wiley & Sons, Inc..
and from
IBM/Rational Course on UML 2.0

Most slides Copyright 2001 © John Wiley & Sons. Others © IBM/Rational.
Slide 1
Objectives
• Understand the rules and style guidelines for
sequence and communication diagrams and
behavioral state machines.
• Understand the processes used to create
sequence and communication diagrams and
behavioral state machines.
• Be able to create sequence and communication
diagrams and behavioral state machines.
• Understand the relationship between the
behavioral models and the structural and
functional models.
Key Ideas
• Behavioral models describe the internal
dynamic aspects of an information system
that supports business processes in an
organization
• Key UML behavioral models are: sequence
diagrams, collaboration diagrams, and
statechart diagrams
CONTEXT: UML DIAGRAMS
The Thirteen (13) UML 2.0 Diagrams
Structural Diagrams
Class
Deployment
Composite Structure

Package Component Object

Behavioral Diagrams

Use Case Activity


State Machine

Interaction Overview Timing

Sequence Communication
UML 2.0 Diagrams
CoffeeMachine

MakeCoffee

Use Case Diagram


MakeTea Customer

<<include>>

TeaMaking

: Customer : Controller : Hardware

FromUser ::Coin ( 10 )

FromUser ::Coffee ()

FillWater ()

WaterOK ()

FillCoffee ()

CoffeeOK ()

HeatWater ()

Warm ()

ToUser :: CupOfCoffee ()

Sequence Diagram Interaction Overview Diagram


UML 2.0 Diagrams
CoffeeMachine Cust CM Customer
MakingCoffee MakingCoffee

WaterOK
Ctrl
Hw
WaterOK/^FillCoffee;
Hardware Coffee/^HeatWater;
Controller
FillCoffee

WaterForCoffee WaterForCoffee
Class Diagram
Statechart Diagram
FromUser
CustbiCtrl

FromUser P2 Ctrl Controller


P1ToUser : P3
ToUser
WaterOK, Warm, CoffeeOK

FillWater, HeatWater, FillCoffee


P4
Hw:Hardware

Architecture Diagram
(Composite Structure)
UML 2.0 Diagrams

Activity Diagram Package Diagram

Component Diagram Deployment Diagram


When to Use Which Diagram?
• UML is not a method or a
process, it is a visual
language
Use
UseCase
Case
Diagram
Diagram

• The different diagrams are


Architecture
Architecture
Sequence
Sequence
Diagram
Diagram like “tools” in a “tool-box”,
Diagram
Diagram
each with a different
intended use
Statechart
Statechart
Class Diagram
Diagram
Class
Diagram
Diagram
CONTEXT: PROCESS MODELS
How Does UML Fit Into a Process?
• UML is the communication language used during the
Analysis and Design Phases – aids communication
between stakeholders and developers
• Using UML a complete, accurate and fully consistent
description of the system can be created
• Using UML allows mistakes and errors to be easily
identified. The process of looping through the system,
removing errors is absolutely essential and
unavoidable, and is described as iteration.
• Iteration occurs within all phases
The Waterfall Process
• Divides the project into well-defined phases with intermediate
milestones
• Each phase depends on the completion of the previous
• The final product is not delivered until all phases are finished
• Works best on small projects
• Waterfall method has many advantages: Analysis
– it is the most direct way to the objective with the
shortest development time and cost possible Design
• However, the drawbacks of this method include:
– little flexibility for scope changes Implementation
– system limitations not being discovered until later in
the development cycle
Test
– clients not being able to see the product until it is
completely finished
The Spiral Process
• The spiral process is an iterative process
– Recognizes the need to visit requirements
analysis/design/implementation/test sequence more than
once
– Several reasons for this:
• Identification and resolution of risks
• Review of earlier “prototype” versions by the user to elicit
feedback.
• Spiral model focus: to address Analysis Design
risks incrementally in order of
priority
• Rounds follow the
waterfall process
Testing Implementation
The Iterative and Incremental Process
• A logical extension to the spiral model, but
more formal and rigorous
• Structured in four phases: Inception,
Elaboration, Construction and Transition

Inception Elaboration Construction Transition


Requirements Phase

Requirements Phase

Requirements Analysis Design Implementation Test


Analysis Phase

Analysis Phase

Requirements Analysis Design Implementation Test


Analysis Phase

Analysis Phase
• Understand the problem domain
• Create a model describing the problem domain
– Free from any technical or implementation details
– Detailed enough to allow simulation on paper or by using a
modeling tool
• Activities:
– Acquire domain knowledge
– Perform use case analysis
– Define the necessary classes and relationships
– Define the behavior and collaboration between classes
– Test the resulting model
Analysis Phase
Deliverables
• Use Case Model with detailed
use case descriptions
– Natural language
– Sequence diagram
– Activity diagram
– State Machine diagram

• Domain Model
– Class diagram showing domain concepts and
their relationships

• System Interface Class Diagram


– Interface Classes
– Signals that compose the interfaces
– Data types used by the signals
Analysis Phase

When is the Analysis Phase Finished?


• When the Use Cases describe the functional
aspects of the System to build
• When the Conceptual Model expresses the
major components of the problem domain
• When the system interface is well defined
• When developers feel comfortable estimating
the time it will take to develop each use case
BEHAVIORAL MODELS
Behavioral Models
• Systems have static &dynamic characteristics
– Structural models describe the static aspects of
the system
– Behavioral models describe the dynamics and
interactions of the system and its components
• Behavioral models describe how the classes
described in the structural models interact in
support of the use cases.
INTERACTION DIAGRAMS
Interaction Diagram Components
• Objects
an instantiation of a class
• Operations
the behaviors of an instance of a class
• Messages
information sent to objects to tell them to execute
one of their behaviors
Kinds of Interaction Diagrams
• Sequence Diagrams
• Communication Diagrams

Copyright 2001 © John Wiley & Sons, Slide 24


Inc. All rights reserved.
Sequence Diagrams
• Model the behavior of use cases by describing
the way groups of objects interact to complete
the task. 
• Show sequences of messages (“interactions”)
between instances in the system
• Each diagram depicts a possible set of messages
only
(a ”scenario”) – not all possible messages
• Are read left to right and descending
• Emphasize time ordering
System Level Sequence Diagrams
• Describe the interaction between the
Actors and the System
– Remember: Black box
• Define the System Interface
• Can be used as System Level Test Cases

Slide 26
Sequence Diagram Syntax
Analysis Phase

Sequence Diagram – elements


OrderCoffee - Basic OrderCoffee

Associated
Use Case

Lifeline

Message name
Use Case
Reference

Message line

cific
spe
TAU
The interaction name and page numbering
is Tau specific
Analysis Phase

Lifelines
• A Lifeline consists of a rectangle that identifies the
connectable element (such as a part or component)
and a vertical line indicating its time of existence
Lifeline of Lifeline of an Lifeline of an
unknown Class Anonymous Object of a
Object known class
More Sequence Diagram Syntax
Sample Sequence Diagram
Analysis Phase

Object Communication
• Messages are labeled with the name of the message
(operation or signal) and its argument values.
• Message parameters can be a data type, a variable or a
constant.
• For correctness the variables and constants must be declared
• To make the interaction more general use data types or
variables as parameters
Data type

Variable

Value
Analysis Phase

Referencing
• To avoid unnecessary duplication it is possible to reuse
already existing Sequence Diagrams
• The name is the Use Case name, not the Sequence
Diagram name.
– A Use Case encapsulates zero or more Sequence, or other
types of diagrams
Steps to Build Sequence Diagrams
(Dennis)
1. Set the context
2. Identify which objects will participate
3. Set the lifeline for each object
4. Lay out the messages from top to bottom of the
diagram based on the order in which they are sent
5. Add execution occurrence to each object‘s lifeline
6. Validate the sequence diagram
Analysis Phase

Steps to System Level Sequence Diagrams


(alternate view)
1. Select a Use Case to model
2. Select a scenario:
– Basic: positive and straightforward behavior
– Alternative
– Exception
3. Add lifelines for the System and each involved Actor
4. Add interactions between the Actors and the System
using arrows
5. Name the arrows using message names and
parameters
– Keep it simple, no need to provide all parameters at this
point
Analysis Phase

Sequence Diagram Guidelines


• Keep the diagram simple
– If it is too complex, perhaps it should be broken
down into separate diagrams
• Don’t capture all the scenarios in one diagram
– One diagram per scenario
INTERACTION OVERVIEW
DIAGRAMS
Slide 37
Analysis Phase

Interaction Overview Diagrams


• A specialized activity diagram that shows how
sequence diagrams can be put together
• Allow you to construct a “roadmap” of sequence
diagrams and navigate easily among them
Analysis Phase
Interaction Overview Diagram
Guidelines
• Keep the diagram simple
– If it is too complex, perhaps it should be broken
down into separate diagrams
• Show how different Sequence Diagrams
interconnect with each other
COMMUNICATION DIAGRAMS
What Is a Communication Diagram?
• A communication diagram emphasizes the
organization of the objects that participate in
an interaction.
• The communication diagram shows:
– The objects participating in the interaction.
– Links between the objects.
– Messages passed between the objects.

Communication Diagrams
Example: Communication Diagram
5: display course offerings( )
6: display blank schedule( )

1: create schedule( ) : Course Catalog


: RegisterForCoursesForm

: Student
2: get course offerings( )
4: get course offerings( )

3: get course offerings(forSemester)

: RegistrationController : CourseCatalogSystem
Communication Diagrams Contents:
Objects
: RegisterForCoursesForm

Objects

: RegistrationController SWTSU Catalog


: CourseCatalogSystem
Communication Diagram Contents:
Actors
: RegisterForCoursesForm

: Student : Course Catalog

Actors

: RegistrationController SWTSU Catalog


: CourseCatalogSystem
Communication Diagram Contents: Links and
Messages
Messages 5: display course offerings( )
6: display blank schedule( )

1: create schedule( ) Links : Course Catalog


: RegisterForCoursesForm

: Student
2: get course offerings( )
4: get course offerings( )

3: get course offerings(forSemester)

: RegistrationController : CourseCatalogSystem
Sequence and Communication
Diagram Similarities
• Semantically equivalent
– Can convert one diagram to the other without
losing any information
• Model the dynamic aspects of a system
• Model a use-case scenario
Sequence and Communication
Diagram Differences
Sequence Communication
diagrams diagrams
 Show the explicit  Show relationships in
sequence of messages addition to interactions
 Show execution  Better for visualizing
occurrence patterns of
 Better for visualizing communication
overall flow  Better for visualizing all
 Better for real-time of the effects on a given
specifications and for object
complex scenarios  Easier to use for
brainstorming sessions
ACTIVITY DIAGRAMS
Analysis Phase

Activity Diagrams
• Activity diagrams describe the workflow behavior
of a system
• Activity diagrams can show activities that are
conditional or parallel.
• Activity Diagrams are useful for:
– analyzing a use case by describing what actions need
to take place and when they should occur 
– describing a complicated sequential algorithm
– modeling applications with parallel processes
– modeling bussiness workflow
Analysis Phase

Activity Diagram - elements


Object Node
Initial Node

Action Node

Fork Join

Activity Final
Decision Node
Guard
Analysis Phase

Activity Diagram Symbols - 1


Initial node
Starting point for invocing other activities. An activity
may have several starting points.

Action/Activity
An action is an executable unit. Can also refer to a new
activity diagram.
Analysis Phase

Action States and Activity States


• Each state in an activity diagrams is either:
– an action state
• describes an atomic action
• the outgoing transitions are implicitly triggered by the
completion of the action in the state
– or an activity state
• describes an enduring activity which can be interrupted
• invokes an activity graph
• the activity state is not exited until the final state of the
nested graph is reached.
Analysis Phase

Activity Diagram Symbols - 2


Object node
Represents an instance of a clasifier, usually a class
Used to show input to or output from an action.
An object flow shows objects being generated or
used by actions or activities in activity diagrams
Analysis Phase

Activity Diagram Symbols - 3


Decision node
A decision node is a control node that chooses
between outgoing flows.
Each branch has its own guard condition
“Else” may be defined for at most one outgoing
transition

Fork/Join symbol
Divides a flow into multiple concurrent flows. Flows can
be split and synchronized again.
Analysis Phase

Activity Diagram Symbols - 4


Connector symbol
Label and Join

Accept event symbol


Represents an input action.

Send signal symbol


Represents an output action.

Accept time event symbol


Represents a timeout situation. To set a timer, use
textual syntax in an action node
Analysis Phase

Activity Diagram Symbols - 5


Activity final symbol
Aborts all flows in the containing activity.

Flow final symbol


Destroys all tokens that arrive at it, but has no effect
on other flows.

Text symbol

// Comment symbol:
• unconnected or unselected it looks almost like a text symbol.
Analysis Phase

Activity Diagram Symbols - 6


Activity Partition (Swim lanes)
Swim lanes visually group the action states. They
have no semantics but are often used to show a
relation between activities, for example activities
performed by a person, business unit etc.
Swimlanes can also contain other swimlanes.
You can also indicate that a swimlane represents a
certain part or that it represents an external entity.
Analysis Phase

Activity Diagram – Swimlane Example


• Transitions can take place from one swim lane
'Prompt For Card'

[Display("Insert Card")]

to another
'Customer Inserts Card'

Card

'Prompt for Pin'

[Display("Enter Pin")]

'Customer Provides Pin'


Pin

ValidateCardandPin

CardInfo

ValidateCardInfo
Analysis Phase
Activity Diagram – Example
Card Inserted

System prompts
for PIN

Guard: Follow this Customer


enters PIN
path, only if the text
in the brackets [ ] Validate PIN
evaluates to true.
[PIN valid] [PIN invalid]

Select Log invalid PIN


transaction type

[NbrOfAttempts < 3]
Prompt
PIN invalid
[Foreign currency
[Withdrawal] transaction]

System prompts System prompts


for amount for currency

Reject card
Customer enters Customer
amount enters currency
Analysis Phase

Activity Diagram Guidelines


• Keep the diagram simple
– The focus is easy communication. Don’t be too formal
• Swimlanes should only represent the Actors and the
System
• All required Object Nodes should be part of the Conceptual
Model
– Revise the Model if necessary
• Try to capture all the scenarios of the Use Case in one
diagram
– But be careful not to overload the diagram. If necessary use
more than one per Use Case
• Emphasize the collaborative and parallel aspects of the
behavior
Analysis Phase

Drawing Activity Diagram


• Remember, this is an iterative process
• Select a Use Case to model
• Look at all scenarios:
– Basic: positive and straightforward behavior
– Alternative
– Exception
• Find the Use Case participants
• Find the main activities
– Internal and Intermediate activities will be defined in later phases
• Find the Decision Criteria that defines the transition between
activities
• Find the Input and the Output for the activities
• Determine which activities are parallel/concurrent and which ones
are sequential
Exercise 8
Analysis Phase

Assignment Build Activity Diagram


• Identify the participating candidates and draw the
associated swim lane

• Identify and define activities

• Identify and define transitions between those activities

• Add the necessary decision nodes that are necessary to


understand the use case

• If pertinent, add the Object Nodes and Flows


BEHAVIORAL STATE MACHINES
Analysis Phase

State Machine Diagram


• A state machine diagram specifies the
dynamic behavior of an element in a reactive,
event-driven way
• Specifies a finite number of states of an
element and how transitions between states
are performed in response to events
• Typically not used for all objects
– Just for complex ones
Analysis Phase

State Machine Diagram Usage


• To elaborate use case specifications
• To specify high-level system behavior during
analysis
• Capture significant events that can act on an
object
Analysis Phase

System Level State Machine Diagram


• Defining a System Level State Machine that
includes all Use Cases would be unrealistic
– Too many system states
– Too many possible transitions
• Instead, a System Level State Machine should be
created to show only some aspects of the
functionality
• Each of these State Machines could be used to do
partial simulation of the System
– On paper
– Using a UML tool
Components of State Machines
• States
values of an object’s attributes at a point in time

• Events
change the values of the object’s attributes

• Transitions
movement of an object from one state to another

• Actions
atomic, non-decomposable processes

• Activities
non-atomic, decomposable processes
State Machine Syntax
Analysis Phase

State Machine Diagram - elements


Initial
state

Transition

Self
transition

State

Final
state
Sample State Machine
Analysis Phase

Transition (1)
event-name ( parameter-list ) [ guard-condition] / action-expression;

Event-name Parameter-list

cific
U spe
TA

The action
Action-expression language in
transitions is
Tau specific

Guard-condition
Analysis Phase

Transition (2)
event-name ( parameter-list ) [ guard-condition] / action-expression;

 incoming-signal-name / signal-output;
Warm / ^FillWater;

 incoming-signal-name ( parameter-list ) /
operation-call;
Coin(faceValue) / Amount = AddCoin ( Amount ,
faceValue );
The variable that will contain the parameter
value, must be declared and visible within the
scope of the state machine
Analysis Phase

Transition (3)
event-name ( parameter-list ) [ guard-condition] / action-expression;

 [ guard-condition] / signal-output
( parameters-list );
[Amount >= drinkCost] /
^theMessage(“Please make your drink selection”);

 incoming-signal-name [guard-condition] /
signal-output;
Tea [Amount < drinkCost] / ^GetTeaBag;
Steps to Build a State Machine
1. Set the context
2. Identify the initial, final, and stable states of
the object
3. Determine the order in which the object will
pass through the stable states
4. Identify the events, actions, and guard
conditions associated with the transitions
5. Validate the behavioral state machine
Analysis Phase

State Machine Diagram Guidelines


• Keep the diagram simple
– If it is too complex, perhaps it should be broken
down into separate diagrams
• Try to capture all the scenarios of a Use Case
in one diagram
– One diagram per Use Case
Analysis Phase

Drawing State Machine Diagrams


• Find the Classes or Use Cases that are important enough to
justify a behavior analysis
• Find the main states
– Internal and Intermediate states will be defined later in the
Design phase
• Find the required transitions to fulfill all the Actors’
requests
• As for the Sequence Diagram, name the incoming request
and answers in a natural language. Message names will be
defined/refined later.
• Do not define sub-state machine
– Keep it simple
– Simply give the short description of the internal state behavior
CRUD ANALYSIS
CRUD Analysis
• Labels object interaction in 4 possible ways
– Create
– Read
– Update
– Delete
• Matrix representation of objects and interactions
• Most useful as a system-wide representation
– Identify complex objects
– Catch omissions
– Group closely related classes
Sample CRUD Matrix

You might also like