Behavioral Modeling with UML 2.0Behavioral Modeling with UML 2.0
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
Class
ObjectComponent
Composite Structure
Deployment
Package
Structural Diagrams
Behavioral Diagrams
Use Case Activity
Interaction Overview
Sequence
State Machine
Timing
Communication
UML 2.0 DiagramsCoffeeMachine
CustomerMakeTea
TeaMaking
<<include>><<include>>
MakeCoffee
: Hardware: Controller: Customer
FromUser ::Coin (10)
FromUser ::Coin (10)
FromUser ::Coffee ()
FromUser ::Coffee ()
FillWater ()
FillWater ()
WaterOK ()
WaterOK ()
FillCoffee ()
FillCoffee ()
CoffeeOK ()
CoffeeOK ()
HeatWater ()
HeatWater ()
Warm ()
Warm ()
ToUser ::CupOfCoffee ()
ToUser ::CupOfCoffee ()
Sequence Diagram
Use Case Diagram
Interaction Overview Diagram
UML 2.0 Diagrams
Statechart Diagram
MakingCoffee
WaterOK
FillCoffee
WaterForCoffee
MakingCoffee
WaterForCoffee
WaterOK/̂ FillCoffee; Coffee/̂HeatWater;Coffee/̂HeatWater;
P1
FromUser
ToUser
Ctrl:Controller
P2P3
Hw:Hardware P4
WaterOK, Warm, CoffeeOK
FillWater, HeatWater, FillCoffee
FromUserToUser
CustbiCtrl
Architecture Diagram(Composite Structure)
CoffeeMachine
Customer
Controller
Hardware
CM
Cust
Ctrl
Hw
Class Diagram
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
• The different diagrams are like “tools” in a “tool-box”, each with a different intended use
Use Case Diagram
Use Case Diagram
StatechartDiagram
StatechartDiagram
Sequence Diagram
Sequence Diagram
Architecture Diagram
Architecture Diagram
ClassDiagram
ClassDiagram
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:
– it is the most direct way to the objective with the shortest development time and cost possible
• However, the drawbacks of this method include:– little flexibility for scope changes– system limitations not being discovered until later in
the development cycle– clients not being able to see the product until it is
completely finished
Analysis
Design
Implementation
Test
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
risks incrementally in order of priority
• Rounds follow the waterfall process
Analysis Design
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
TransitionConstructionElaborationInception
Requirements Phase
ImplementationDesignAnalysisRequirements Test
Requirements Phase
Analysis Phase
ImplementationDesignRequirements TestAnalysis
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
• 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
DeliverablesAnalysis 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
Analysis Phase
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
• Objectsan instantiation of a class
• Operationsthe behaviors of an instance of a class
• Messagesinformation 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, Inc. All rights reserved.
Slide 24
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
Sequence Diagram – elements
Lifeline
Associated Use Case
Use Case Reference
Message line
Message name
Analysis Phase
OrderCoffee
OrderCoffee - Basic
TAU specific
The interaction name and page numbering is Tau specific
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 unknown Class
Lifeline of an Anonymous Object
Lifeline of an Object of a known class
Analysis Phase
More Sequence Diagram Syntax
Sample Sequence Diagram
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
Analysis Phase
Data type
Variable
Value
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
Analysis Phase
Steps to Build Sequence Diagrams(Dennis)
1. Set the context2. Identify which objects will participate3. Set the lifeline for each object4. Lay out the messages from top to bottom of the
diagram based on the order in which they are sent5. Add execution occurrence to each object‘s lifeline6. Validate the sequence diagram
Steps to System Level Sequence Diagrams(alternate view)
1. Select a Use Case to model2. Select a scenario:
– Basic: positive and straightforward behavior– Alternative– Exception
3. Add lifelines for the System and each involved Actor4. Add interactions between the Actors and the System
using arrows5. 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
Analysis Phase
INTERACTION OVERVIEW DIAGRAMS
Slide 37
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
Analysis Phase
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
: Student
: RegisterForCoursesForm
: RegistrationController : CourseCatalogSystem
5: display course offerings( )6: display blank schedule( )
: Course Catalog1: create schedule( )
2: get course offerings( )
3: get course offerings(forSemester)
4: get course offerings( )
Communication Diagrams Contents: Objects
Objects
: RegisterForCoursesForm
: RegistrationController SWTSU Catalog : CourseCatalogSystem
Communication Diagram Contents: Actors
: Student : Course Catalog
: RegisterForCoursesForm
: RegistrationController SWTSU Catalog : CourseCatalogSystem
Actors
Communication Diagram Contents: Links and Messages
: Student
: RegisterForCoursesForm
: RegistrationController : CourseCatalogSystem
5: display course offerings( )
6: display blank schedule( )
: Course Catalog1: create schedule( )
2: get course offerings( )
3: get course offerings(forSemester)
4: get course offerings( )
Links
Messages
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 diagrams
Communication diagrams
Show the explicit sequence of messages
Show execution occurrence
Better for visualizing overall flow
Better for real-time specifications and for complex scenarios
Show relationships in addition to interactions
Better for visualizing patterns of communication
Better for visualizing all of the effects on a given object
Easier to use for brainstorming sessions
ACTIVITY DIAGRAMS
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 - elementsAnalysis Phase
Fork Join
Decision Node
Object Node
Action Node
Initial Node
Activity Final
Guard
Activity Diagram Symbols - 1Initial nodeStarting point for invocing other activities. An activity may have several starting points.
Action/ActivityAn action is an executable unit. Can also refer to a new activity diagram.
Activity2
if (a) { x = 7; }
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
Class3
Object nodeRepresents an instance of a clasifier, usually a classUsed 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
UpdateOrder
UpdateOrder
CustomerOrderCustomerOrder
PrepareInvoice
PrepareInvoice
Activity Diagram Symbols - 3Decision nodeA 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
x
Fork/Join symbolDivides a flow into multiple concurrent flows. Flows can be split and synchronized again.
Analysis Phase
Activity Diagram Symbols - 4
Connector symbolLabel and Join
Signal12
Accept event symbolRepresents an input action.
Send signal symbolRepresents an output action.
Accept time event symbolRepresents a timeout situation. To set a timer, use textual syntax in an action node
Analysis Phase
Activity Diagram Symbols - 5Activity final symbolAborts all flows in the containing activity.
Flow final symbolDestroys all tokens that arrive at it, but has no effect on other flows.
Integer i; Text symbol
Comment symbol: • unconnected or unselected it looks almost like a text symbol.
Analysis Phase
//MyComment
Activity Diagram Symbols - 6SL1
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.SL3
SL3
SL2
SL2
SL1c3:Class3
<<external>>
SL1c3:Class3
<<external>>
Analysis Phase
Activity Diagram – Swimlane Example
• Transitions can take place from one swim lane to another
Analysis Phase
AccountList
ControlUnit
Customer
'Prompt For Card'
[Display("Insert Card")]
[Display("Insert Card")]
'Customer Inserts Card'
Card
'Prompt for Pin'
[Display("Enter Pin")]
[Display("Enter Pin")]
'Customer Provides Pin'
ValidateCardandPin
Pin
CardInfo
ValidateCardInfo
Activity Diagram – Example
Card Inserted
System promptsfor PIN
Customerenters PIN
Log invalid PIN
Validate PIN
Selecttransaction type
Prompt PIN invalid
[PIN invalid][PIN valid]
Reject card
[NbrOfAttempts < 3]
System promptsfor amount
System promptsfor currency
[Withdrawal] [Foreign currencytransaction]
Customer entersamount
Customerenters currency
Analysis Phase
Guard: Follow this path, only if the text in the brackets [ ] evaluates to true.
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
Analysis Phase
Exercise 8
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
Analysis Phase
BEHAVIORAL STATE MACHINES
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
Analysis Phase
Components of State Machines
• Statesvalues of an object’s attributes at a point in time
• Eventschange the values of the object’s attributes
• Transitionsmovement of an object from one state to another
• Actionsatomic, non-decomposable processes
• Activitiesnon-atomic, decomposable processes
State Machine Syntax
State Machine Diagram - elements
Initialstate
State
Self transition
Transition
Finalstate
Analysis Phase
Sample State Machine
Transition (1)event-name ( parameter-list ) [ guard-condition] / action-expression;
Guard-condition
Event-name
Action-expression
Parameter-list
Analysis Phase
TAU specific
The action language in transitions is Tau specific
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
Transition (2)event-name ( parameter-list ) [ guard-condition] / action-expression;
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;
Analysis Phase
Steps to Build a State Machine
1. Set the context2. Identify the initial, final, and stable states of
the object3. Determine the order in which the object will
pass through the stable states4. Identify the events, actions, and guard
conditions associated with the transitions5. Validate the behavioral state machine
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
Analysis Phase
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