Beruflich Dokumente
Kultur Dokumente
Behavioral Elements
Model
Management
Common
Behavior
Foundation
2
Use Case Modeling
What is use case modeling?
Core concepts
Diagram tour
When to model use cases
Modeling tips
Example: Online HR System
3
What is use case modeling?
use case model: a view of a
system that emphasizes the
behavior as it appears to
outside users. A use case
model partitions system
functionality into transactions
(‘use cases’) that are
meaningful to users (‘actors’).
4
Use Case Modeling: Core
Elements
system
with these use cases.
5
Use Case Modeling: Core
Relationships
6
Use Case Modeling: Core Relationships
(cont’d)
7
Use Case Diagram Tour
8
Use Case Diagram
Telephone Catalog
Check
status
Place Salesperson
order
F ill o r d e r s
Establish
credit
Supervisor
Supply Order
Customer Data Product Arrange
Payment
Place Order
R
Fig. 3-54, UML Notation Guide
10
Actor Relationships
1 * Place
Order
Salesperson
Establish
1 *
Credit
Fig. 3-55, UML Notation Guide
Supervisor 11
Use Case Description: Change Flight
■Actors: traveler, client account db, airline reservation system
■Preconditions:
•…
■Alternative courses
• If no flights are available then …
12
When to model use cases
Model user requirements with use
cases.
Model test scenarios with use cases.
If you are using a use-case driven
method
start with use cases and derive your
structural and behavioral models from it.
If you are not using a use-case driven
method
make sure that your use cases are
consistent with your structural and
behavioral models.
13
Use Case Modeling Tips
Make sure that each use case describes a significant
chunk of system usage that is understandable by both
domain experts and programmers
When defining use cases in text, use nouns and verbs
accurately and consistently to help derive objects and
messages for interaction diagrams
Factor out common usages that are required by multiple
use cases
If the usage is required use <<include>>
If the base use case is complete and the usage may be
optional, consider use <<extend>>
A use case diagram should
contain only use cases at the same level of abstraction
include only actors who are required
Large numbers of use cases should be organized into
packages
14
Example: Online HR System
15
Online HR System: Use Case
Relationships
U p
16
Online HR System: Update Benefits Use
Case
■Actors : employee, employee account db, healthcare plan system,
insurance plan system
■Preconditions:
■Alternative courses
• If health plan is not available in the employee’s area the employee is
informed and asked to select another plan...
17
State Machines Overview
Basic State Machine Concepts
Statecharts and Objects
Advanced Modeling Concepts
Wrap Up
18
Automata
A machine whose output behavior is not
only a direct consequence of the current
input, but of some past history of its
inputs
Characterized by an internal state which
represents this past experience
ON
ON ON
OFF
19
State Machine (Automaton)
Diagram
Graphical rendering of automata
behavior on
Lamp On
on
off
off
Lamp Off
20
Outputs and Actions
As the automaton changes state it
can generate outputs:
on on
Lamp On
Lamp On print(”on”)
on/print(”on”) on
off off
off off
Lamp Lamp
Off Off
21
Extended State Machines
Addition of variables (“extended
state”)
on
ctr : Integer
Lamp On
on/ctr := ctr + 1
off
off
Lamp Off
22
A Bit of Theory
An extended (Mealy) state machine is
defined by:
a set of input signals (input alphabet)
a set of output signals (output alphabet)
a set of states
a set of transitions
triggering signal
action
a set of extended state variables
an initial state designation
a set of final states (if terminating
automaton)
23
Diagram
“top” state
State
Initial
pseudostate top
Trigger
Ready
Transition
stop /ctr := 0
Done
Final
Action
state
stop
24
What Kind of Behavior?
In general, state machines are
suitable for describing event-
driven, discrete behavior
inappropriate for modeling continuous
behavior
threshold
time
25
Event-Driven Behavior
Event = a type of observable occurrence
interactions:
synchronous object operation invocation (call event)
asynchronous signal reception (signal event)
occurrence of time instants (time event)
interval expiry
calendar/clock time
change in value of some entity (change event)
Event Instance = an instance of an event (type)
occurs at a particular time instant and has no duration
26
The Behavior of What?
In principle, anything that manifests
event-driven behavior
NB: there is no support currently in UML
for modeling continuous behavior
In practice:
the behavior of individual objects
object interactions
The dynamic semantics of UML state
machines are currently mainly
specified for the case of active objects
27
Basic State Machine Concepts
Statecharts and Objects
Advanced Modeling Concepts
Wrap Up
28
Model
Simple server model:
Initialize
Initialize
Handling
Handling depends
depends on
on Object
Object
specific
specific request
request type
type
Wait
Waitfor
for
Request
Request
Terminate
Terminate
Object
Object
29
Object Behavior and State
Machines
Direct mapping:
on
Initialize
Object
Lamp On
Wait for
Event on/print(”on”)
Handle
Event
off
off
Lamp
Off
Terminate
Object
stop
30
Object and Threads
Wait
Waitfor
for Wait
Waitfor
for
Request
Request Request
Request
Handle
Handle Handle
Handle
Request
Request Request
Request
Terminate
Terminate Terminate
Terminate
Object
Object Object
Object
31
Passive Objects: Dynamic
Semantics
Initialize
Initialize
Object
Object
Wait
Waitfor
for
Request
Request
Handle
Handle
Request
Request
Terminate
Terminate
Object
Object
32
Active Objects and State
Machines
Objects that encapsulate own
thread of execution
anActiveObject
#currentEvent : Eventpoll/defer
created
+ start ( )
start start/^master.ready() ready
+ poll ( )
+ stop ( )
ready
stop/
poll/^master.ack()
33
Active Objects: Dynamic
Semantics
ActiveObject:
Run-to-completion model:
•serialized event handling
•eliminates internal concurrency
•minimal context switching overhead
34
The Run-to-Completion Model
A high priority event for (another) active
object will preempt an active object that
is handling a low-priority event
Active1
Active1 Active2
Active2
lo
hi
hi
35
Basic State Machine Concepts
Statecharts and Objects
Advanced Modeling Concepts
Wrap Up
36
State Entry and Exit Actions
A dynamic assertion mechanism
LampOn
e2
entry/lamp.on();
exit/lamp.off();
e1
37
Order of Actions: Simple Case
Exit actions prefix transition
actions
Entry action postfix transition
LampOn LampOff
actions off/printf(“to off”); entry/lamp.off();
entry/lamp.on(); entry/lamp.off();
exit/printf(“exiting”); exit/printf(“exiting”);
Internal transition
triggered by
an “off” event LampOff
entry/lamp.off();
exit/printf(“exiting”);
off/null;
39
State (“Do”) Activities
Forks a concurrent thread that
executes until:
the action completes or
the state is exited through an
outgoing transition
“do” activity
Error
entry/printf(“error!”)
do/while (true) alarm.ring();
40
Guards
Conditional execution of transitions
guards (Boolean predicates) must be side-effect free
bid [value < 100] /reject
Unhappy
41
Static Conditional Branching
Merely a graphical shortcut for
convenient rendering of decision
trees
Selling Happy
bid
Unhappy
42
Branching
Choice pseudostate: guards are
evaluated at the instant when the
decision point is reached
Selling Happy
43
Hierarchical State Machines
Graduated attack on complexity
states decomposed into state
machines
LampOff
flash/ LampFlashing
entry/lamp.off()
FlashOn
off/ entry/lamp.on()
1sec/
1sec/
on/ on/
FlashOff
LampOn
on/
entry/lamp.off()
entry/lamp.on()
44
“Stub” Notation
Notational shortcut: no semantic
significance
LampOff
flash/ LampFlashing
entry/lamp.off()
off/ FlashOn
on/ on/
LampOn
on/ FlashOff
entry/lamp.on()
45
Group Transitions
Higher-level transitions
Default transition to
the initial pseudostate
LampOff
flash/ LampFlashing
entry/lamp.off()
FlashOn
off/ entry/lamp.on()
1sec/
1sec/
on/
FlashOff
LampOn
on/
entry/lamp.off()
entry/lamp.on()
Group transition
46
Completion Transitions
Triggered by a completion event
generated automatically when an
immediately nested state machine
terminates
completion
Committing transition (no trigger)
Phase1
Phase1
CommitDone
Phase2
Phase2
47
Triggering Rules
Two or more transitions may have the
same event trigger
innermost transition takes precedence
event is discarded whether or not it triggers
a transition
LampFlashing
FlashOn
on/
off/
on/
FlashOff
48
Deferred Events
Events can be retained if they do
not trigger a transition
off/
on/
LampOn
entry/lamp.on()
49
Case
Same approach as for the simple
case
S1 S2
exit/exS1 entry/enS2
initS2
S11 E/actE S21
exit/exS11 entry/enS21
50
History
Return to a previously visited
hierarchical state
deep and shallow history options
Diagnosing
suspend/
Diagnostic1 Diagnostic2
Step11
Step11 Step21
Step21
resume/ Step12
Step12 Step22
Step22
H*
H*
51
Orthogonality
Multiple simultaneous perspectives on
age
the same entity
financialStatus
Child
Poor
Adult
Rich
Retiree
52
Orthogonal Regions
Combine multiple simultaneous
age descriptions financialStatus
Child
Poor
Adult
age financialStatus
Child Rich
Retiree
Poor
Adult
Retiree Rich
53
Semantics
All mutually orthogonal regions detect
the same events and respond to them
“simultaneously”
usually reduces to interleaving of some kind
legalStatus financialStatus
LawAbiding Poor
robBank/ robBank/
Outlaw Rich
54
Interactions Between Regions
Typically through shared variables or
awareness of other regions’ state
changes sane
sane :: Boolean
Boolean
flying
flying :: Boolean
Boolean
Catch22
Catch22
sanityStatus flightStatus
Crazy Flying
entry/sane
entry/sane :=
:= false;
false; entry/flying
entry/flying :=
:= true;
true;
(flying)/ (sane)/
request
Grounding/ (~sane)/
Sane Grounded
entry/sane
entry/sane :=
:= true;
true; entry/flying
entry/flying :=
:= false;
false;
55
Transition Forks and Joins
For transitions into/out of
orthogonal regions:
age
Child
Child Adult
Adult Retiree
Retiree
Staff
Staff Manager
Manager
Member
Member
employee
56
Orthogonality
Using regions to model independent
objects
Person1 Person2
Person1 Person2
Child Child
Adult Adult
Retiree Retiree
57
Basic State Machine Concepts
Statecharts and Objects
Advanced Modeling Concepts
Wrap Up
58
Wrap Up: Statecharts
UML uses an object-oriented variant of
Harel’s statecharts
adjusted to software modeling needs
Used to model event-driven (reactive)
behavior
well-suited to the server model inherent in
the object paradigm
Primary use for modeling the behavior of
active event-driven objects
systems modeled as networks of
collaborating state machines
run-to-completion paradigm significantly
simplifies concurrency management
59
Wrap Up: Statecharts (cont’d)
Includes a number of sophisticated
features that realize common state-
machine usage patterns:
entry/exit actions
state activities
dynamic and static conditional branching
Also, provides hierarchical modeling for
dealing with very complex systems
hierarchical states
hierarchical transitions
orthogonality
60
Activity Diagram Applications
Intended for applications that need
control flow or object/data flow models
…
... rather than event-driven models like
state machines.
For example: business process modeling
and workflow.
The difference in the three models is
how step in a process is initiated,
especially with respect to how the step
gets its inputs.
61
Activity Diagrams Based on State
Machines
62
Diagrams
Action (State) Action
63
Action (State)
Action
Subactivity
Deliver Mail
POEmployee
66
Activity Graph as Method
POEmployee.sortMail POEmployee.deliverMail
POEmployee
PO Employee Deliver Mail Method
sortMail()
«realize»
deliverMail() Check Out Put Mail
Truck In Boxes
Action/Subactivity *
Applies to actions and subactivities.
Not inherited from state machines.
Invokes an action or subactivity any number of times in
parallel, as determined by an expression evaluated at
runtime. Expression also determines arguments.
Upper right-hand corner shows a multiplicity restricting
the number of parallel invocations.
Outgoing transition triggered when all invocations are
done.
Currently no standard notation for concurrency
expression or how arguments are accessed by actions.
Attach a note as workaround for expression. Issue for
UML 2.0. 68
Object Flow (State)
Class
[State]
Order
Take Order Fill Order
[Taken]
70
Coordinating Steps
Inherited from state machines
Initial state
Final state
71
Coordinating Steps
Decision point and merge ( ) are
inherited from state machines.
For modeling conventional flow
chart decisions.
Get
Authorization
72
Coordinating Steps
Synch state ( ) is inherited from state
machines but used mostly in activity
graphs.
Provides communication capability
State machine between parallel processes.
notation Put
Build Install
Frame On Walls
Roof
Install
Inspect
Foundation
* *
Install Install
Install
Electricity Electricity
Electricity
in Foundation In Frame
Outside
73
Convenience Features (Synch
State)
Forks and joins do not require
composite states.
Synch states may be omitted for the
common case (unlimited bound and one
incoming and outgoing transition).
Activity diagram
notation Put
Build Install
On
Frame Walls
Roof
Install Inspect
Foundation
74
Convenience Features (Synch
State)
Object flow states can be synch
states
75
Release
Release Fix
Fix
76
Convenience Features
Fork transitions can have guards.
Test
Revise Fix
Revise Test Plan
Plan Fix
Instead of doing this:
Evaluate
Fix
Impact
Bug
Evaluate Fix
Impact Bug
[else]
[ priority = 1]
[ priority = 1]
Register
Register Bug
Bug
Convenience Features
Partitions are a grouping mechanism.
semantics.
Tools can generate swimlane presentation
Revise
Impact
Plan
[ priority = 1]
Support
Register
Release
Bug
Fix
Engineering Test
Bug
Fix
Fix
77
Convenience Features
Signal send icon
Wake Up
Signal
Get Cups
Signal receipt icon Coffee
Pot
Signal
Coffee Done
… translates to a wait
state (a state with no
Drink Coffee
action and a signal trigger
event).
78
Case Study partition
initial state
action state control flow
Begin
fork of control
Develop
technology Issue RFP
specification
RFP
[issued]
conditional
fork join of control
Submit
specification
draft object flow
Specification
[optional] input value
[initial
October 1999
Communications of the ACM
Kobryn, “UML 2001”
Adapted from
proposal]
Collaborate with
competitive
submitters
Evaluate initial
submissions
Finalize
specification
Specification
[final
proposal]
79
Collaborate with
competitive
submitters Evaluate initial
submissions
Finalize
specification
Specification
[final
Case
proposal]
Evaluate final
submissions
Vote to
recommend
guard
Revise
October 1999
Communications of the ACM
Kobryn, “UML 2001”
Adapted from
specification
Implement
specification
Specification
[revised]
Enhance
Recommend
specification
revision
[else] [Enhanced]
final state
80
Diagrams
Use activity diagrams when the behavior you
are modeling ...
does not depend much on external events.
mostly has steps that run to completion, rather
than being interrupted by events.
requires object/data flow between steps.
is being constructed at a stage when you are
more concerned with which activities happen,
rather than which objects are responsible for
them (except partitions possibly).
81
Tips
Control flow and object flow are
not separate. Both are modeled
with state transitions.
Dashed object flow lines are also
control flow.
You can mix state machine and
control/object flow constructs on
the same diagram (though you
probably do not want to).
82
Tips
Request
Return
Get Return
Number
Ship Item
Receive
Item
Item
[returned]
Restock
Item
Credit Item
Account [available]
83
Customer Telesales Accounting Warehouse
Request
Return
Activity Modeling Tips
Get Return
Number
Ship Item
Receive
Item Item
[returned]
Restock
Item
Credit
Account Item
[available]
84
Tips
Activity diagrams inherit from state machines
the requirement for well-structured nesting of
composite states.
85
Tips
Well-nested:
86
Tips
Not well-nested:
87
Tips
88
Wrap Up: Activity Diagrams
Use Activity Diagrams for applications that are
primarily control and data-driven, like business
modeling …
… rather than event-driven applications like
embedded systems.
Activity diagrams are a kind of state machine
until UML 2.0 …
… so control and object/data flow do not have
separate semantics.
UML 1.3 has new features for business
modeling that increase power and
convenience. Check it out and give feedback!
89