Professional Documents
Culture Documents
Behavioral Modeling
Gunnar vergaard, Bran Selic and Conrad Bock January 2000
1999 OMG and Tutorial Contributors: EDS, IBM, Enea Data, IntelliCorp, Klasse Objecten, ObjectTime Ltd., Rational Software, Unisys
Overview
Tutorial series UML Quick Tour Behavioral Modeling Part 1: Interactions and Collaborations
Gunnar vergaard, Rational Software Bran Selic, ObjecTime Limited Conrad Bock, IntelliCorp
Part 2: Statecharts
Tutorial Series
Introduction to UML
November 1999, Cambridge, US January 2000, Mesa, Arizona, US March 2000, Denver, US June 2000, Oslo, Norway
Tutorial Goals
What you will learn:
what the UML is and what is it not UMLs basic constructs, rules and diagram techniques how the UML can model large, complex systems how the UML can specify systems in an implementationindependent manner how UML, XMI and MOF can facilitate metadata integration Object Modeling Development Methods or Processes Metamodeling
the artifacts of software systems Added to the list of OMG adopted technologies in November 1997 as UML 1.1 Most recent minor revision is UML 1.3 (November 1999)
UML Goals
Define an easy-to-learn but semantically rich visual
modeling language Unify the Booch, OMT, and Objectory modeling languages Include ideas from other modeling languages Incorporate industry best practices Address contemporary software development issues
Provide flexibility for applying different processes Enable model interchange and define repository
interfaces
Q3 1999
Q2 1998
Software Development Processes Business Modeling UML CORBAfacility Interface Definition UML XML Metadata Interchange DTD Object Constraint Language
syntax = language elements (e.g. words) are assembled into expressions (e.g. phrases, clauses) semantics = the meanings of the syntactic expressions
Unifying Concepts
classifier-instance dichotomy
e.g. an object is an instance of a class OR a class is the classifier of an object e.g. an interface is a specification of a class OR a class is a realization of an interface
specification-realization dichotomy
10
Language Architecture
Metamodel architecture Package structure
11
Metamodel Architecture
<<m e ta m ode l>> MOF Me ta m e ta m ode l M eta-M etam odel Lay er (M 3): S pec ifies m etam etac las s es for the UM L m etam odel
M etam odel Lay er (M 2): S pec ifies m etac las s es for the UM L m etam odel, s uc h as Clas s
Use r Mode l
M odel Lay er (M 1): S pec ifies c las s es for the UM L us er m odels , s uc h as P as s enger, Tic k et, TravelA genc y
:Foo
:B ar
:B az
Us er O bjec ts Lay er (M 0): Us er objec ts that are ins tanc es of UM L us er m odel c las s es , s uc h as ins tanc es of P as s enger, Tic k et, TravelA genc y
12
Package Structure
dependency
Foundation
package
13
Package Structure
Behavioral Elements
Collaborations
Use Cases
State Machines
Common Behavior
Foundation
14
Behavioral Modeling
Part 1: Interactions and Collaborations
Gunnar vergaard, Rational Software gunnaro@it.kth.se
15
Interactions
What are interactions? Core concepts Diagram tour When to model interactions Modeling tips Example: A Booking System
16
between instances, including all ways to affect instances, like operation invocation, as well as creation and destruction of instances The communications are partially ordered (in time)
17
Description
An entity with a unique identity and to which a set of operations can be applied (signals be sent) and which has a state that stores the effects of the operations (the signals). A specification of an executable statement. A few different kinds of actions are predefined, e.g. CreateAction, CallAction, DestroyAction, and UninterpretedAction.
Syntax
name attr values
textual
18
Description
A communication between two instances. A declaration of a service that can be requested from an instance to effect behavior. A specification of an asynchronous stimulus communicated between instances.
Syntax
textual
Signal
19
Construct
Link
Description
A connection between instances.
Syntax
Attribute Link A named slot in an instance, which holds the value of an attribute.
textual
20
Example: Instance
underlined name
triangle : Polygon
triangle : Polygon
center : Point = (2,2) vertices : Point* = ((0,0), (4, 0), (2,4)) borderColor : Color = black fillColor : Color = white
triangle
attribute links
: Polygon
21
: Family
Joe : Person
husband
wife
Jill : Person
22
Triangle
+ move (in dist : Point) + scale (in factor : Real) foreach v in vertices do v.x := v.x + dist.x; v.y := v.y + dist.y
23
model
graph of instances (possibly including links) and stimuli existing instances creation and deletion of instances
Kinds sequence diagram (temporal focus) collaboration diagram (structural focus)
24
Interaction Diagrams
Sequence Diagram
x a b 1.1.1: b c z y z x
Collaboration Diagram
1.1: a 1.2: c y
25
Sequence Diagram
object symbol lifeline
name () name : Class other
stimulus
activation
new () : Class
delete
return
create
26
Arrow Label
predecessor guard-condition sequence-expression return-value := message-name argument-list
move (5, 7) 3.7.4: move (5, 7) A3, B4 / [ x < 0 ] C3.1: res := getLocation (fig)
3.7 *[1..5]: move (5, 7)
predecessor guard sequence number return value message name iteration argument list condition
27
28
Flat Flow
caller exchange callee
lift receiver dial tone dial digit dial digit
Asynchronous Flow
appl err handl alarm
: Article
unknown alarm
getName
ringing tone
29
iterate ()
30
Collaboration Diagram
object symbol stimulus
redisplay () : Controller
link symbol
window
standard stereotype
: Window window parameter 1.1.3.1 add (self) contents {new} local line {new} : Line
1: displayPositions (window) 1.1 *[i := 1..n]: drawSegment (i) wire wire :Wire self
standard stereotype
standard constraint
standard stereotype
1.1.2: create (r0, r1) 1.1.3: display (window) 1.1.1b: r1 := position () right : Bead
standard constraint
31
with each other. To identify the interfaces of the classifiers. To distribute the requirements.
32
relevant. Express the flow from left to right and from top to bottom. Put active instances to the left/top and passive ones to the right/bottom. Use sequence diagrams
to show the explicit ordering between the stimuli when modeling real-time
Use collaboration diagrams when structure is important to concentrate on the effects on the instances
33
34
Alternative course:
T If no flights are available then
35
change flight itinerary get customer account get itinerary present itinerary select segment present detailed info update information available flight
: :
36
1: change flight itinerary 5: select segment 7: update information : Booking System 4: present itinerary Traveler 6: present detailed info
37
Collaboration
What is a collaboration? Core concepts Diagram tour When to model collaborations Modeling tips Example: A Booking System
38
What is a collaboration?
Collaboration: a collaboration defines the
roles a set of instances play when performing a particular task, like an operation or a use case. Interaction:an interaction specifies a communication pattern to be performed by instances playing the roles of a collaboration.
39
Description
A collaboration describes how an operation or a classifier, like a use case, is realized by a set of classifiers and associations used in a specific way. The collaboration defines a set of roles to be played by instances and links, as well as a set of interactions that define the communication patterns between the instances when they play the roles.
Syntax
Name
40
Description
A classifier role is a specific role played by a participant in a collaboration. It specifies a restricted view of a classifier, defined by what is required in the collaboration. A message specifies one communication between instances. It is a part of the communication pattern given by an interaction.
Syntax
/ Name
Message
label
41
Description
An association role is a specific usage of an association needed in a collaboration. A generalization is a taxonomic relationship between a more general element and a more specific element. The more specific element is fully consistent with the more general element.
Syntax
Generalization
42
Classifier-Instance-Role Trichotomy
An Instance is an entity
with behavior and a state, and has a unqiue identity. A Classifier is a description of an Instance. A Classifier Role defines a usage (an abstraction) of an Instance.
id originates from
ClassName conforms to
/ RoleName
view of
43
ClassifierRole
Attribute-1 Attribute-2 originates from conforms to Operation-1 () Operation-3 ()
Instance
AttributeValue-1 AttributeValue-2 AttributeValue-3
The attribute values of an Instance corresponds to the attributes of its Classifier. All attributes required by the ClassifierRole have corresponding attribute values in the Instance. All operations defined in the Instances Classifier can be applied to the Instance. All operations required by the ClassifierRole are applicable to the Instance.
Behavioral Modeling with UML 44
Example:
/ Parent : Person
/ Parent
: Person
instanceName / ClassifierRoleName : ClassifierName Example: : Person Charlie / Parent Charlie Charlie : Person Charlie / Parent : Person
45
Class-1
view of
Class-2
view of
/ Role-1
{frozen}
3..4
/ Role-2
ClassifierRole
AssociationRole ClassifierRole
An Association Role specifies the required properties of a Link used in a Collaboration. The properties of an AssociationEnd may be restricted by a AssociationEndRole.
Behavioral Modeling with UML 46
Example: A School
/ Teacher : Person position : Text 1 lecturer given course * 1 tutor student * / Student : Person program : Text
47
Resulting multiplicity
Person name : Text position : Text program : Text 1 * Course * * 0..1
Resulting multiplicity
48
CollaborationName
roleName-1
roleName-2
roleName-3
Classifier-1
Classifier-2
49
Patterns in UML
Constraint that must be fulfilled in each instance of this pattern.
Handler.reading = length (Subject.queue) Handler.range = {0..Subject.capacity}
Observer
Subject Handler
CallQueue queue : List of Call source : Object waitAlarm : Alarm capacity : Integer
50
Manager
Controller
All roles defined in the parent are present in the child. Some of the parents roles may be overridden in the child. An overridden role is usually the parent of the new role.
51
Collaborations explicitly
52
/ Teacher : Person 1 tutor position : Text faculty member * faculty 1 : Faculty 1 lecturer
student * / Student : Person program : Text * participant given course * : Course * taken course
53
54
Collaboration Diagram
1.1: a 1.2: c y
55
/ Generator
Constraining Element (A Generalization is not an AssociationRole )
: Printer Device
: Laser Printer
: Line Printer
56
Handler SlidingBarIcon
Manager
Controller
57
Classifiers. Trace a Use Case / Operation onto Classifiers. Map the specification of a Subsystem onto its realization (Tutorial 3).
58
and behavior relevant for the task. A role is an abstraction of an instance, it is not a class. Look for
initiators (external) handlers (active) managed entities (passive)
59
60
Alternative course:
T If no flights are available then
61
/ ARS Protocol
62
identification of classifiers specification of the usage of instances expressing a mapping between different levels of abstraction
structure
63
Behavioral Modeling
Part 1: Interactions and Collaborations Part 2: Statecharts
Bran Selic, ObjecTime Limited bran@objectime.com
64
Overview
Basic State Machine Concepts Statecharts and Objects Advanced Modeling Concepts Case Study Wrap Up
65
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 ON
OFF OFF
66
67
outputs:
on Lamp On on/print(on) off Lamp Off off off Lamp Off Lamp On print(on) on off on
Mealy automaton
Moore automaton
68
69
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
a set of extended state variables an initial state designation a set of final states (if terminating automaton)
State Trigger
Ready
Transition
stop /ctr := 0
Final state
Done
Action Action
stop
71
threshold
time
72
Event-Driven Behavior
Event = a type of observable occurrence
interactions:
synchronous object operation invocation (call event) asynchronous signal reception (signal event)
change in value of some entity (change event) occurs at a particular time instant and has no duration
Behavioral Modeling with UML 73
driven behavior
In practice:
Basic State Machine Concepts Statecharts and Objects Advanced Modeling Concepts Case Study Wrap Up
75
Initialize Initialize Object Object Wait for Wait for Request Request
Terminate Object
stop
77
concurrency conflicts!
start
start/^master.ready()
ready
ready
stop/
poll/^master.ack()
80
handling
eliminates internal concurrency minimal context switching overhead
lo hi hi
82
Basic State Machine Concepts Statecharts and Objects Advanced Modeling Concepts Case Study Wrap Up
83
LampOn
entry/lamp.on(); exit/lamp.off();
e2
e1
84
off/printf(to off);
LampOff
entry/lamp.off(); exit/printf(exiting);
Internal Transitions
Self-transitions that bypass entry and exit actions
Internal transition triggered by an off event
LampOff
entry/lamp.off(); exit/printf(exiting); off/null;
86
do activity Error
entry/printf(error!) do/while (true) alarm.ring();
87
Guards
Conditional execution of transitions guards (Boolean predicates) must be side-effect free
bid [value < 100] /reject bid [value >= 200] /sell
Selling
Happy
Unhappy
Behavioral Modeling with UML 88
Happy
Unhappy
Behavioral Modeling with UML 89
bid /gain := calculatePotentialGain(value) [gain >= 200] /sell [gain < 100] /reject [(gain >= 100) & (gain < 200)] /sell Dynamic Dynamic choicepoint choicepoint
Unhappy
Behavioral Modeling with UML 90
flash/
LampFlashing
FlashOn FlashOn
entry/lamp.on()
off/ on/
LampOn LampOn
entry/lamp.on()
91
Stub Notation
Notational shortcut: no semantic significance
LampOff LampOff
entry/lamp.off()
flash/
LampFlashing
FlashOn
off/ on/
LampOn LampOn
entry/lamp.on()
on/ on/
FlashOff
92
Group Transitions
Higher-level transitions
Default transition to Default transition to the initial pseudostate the initial pseudostate
LampOff LampOff
entry/lamp.off()
flash/
LampFlashing
FlashOn FlashOn
entry/lamp.on()
off/ on/
LampOn LampOn
entry/lamp.on()
FlashOff FlashOff
entry/lamp.off()
Completion Transitions
Triggered by a completion event generated automatically when an immediately nested state machine terminates
Committing
Phase1 Phase1
CommitDone
Phase2 Phase2
94
Triggering Rules
Two or more transitions may have the same
event trigger
innermost transition takes precedence if no transition is triggered, event is discarded
LampFlashing
FlashOn FlashOn
95
History
Return to a previously visited hierarchical state
suspend/
Diagnostic1 Diagnostic1
Step11 Step11
Diagnostic2 Diagnostic2
Step21 Step21
resume/
H* H*
Step12 Step12
Step22 Step22
97
Orthogonality
Multiple simultaneous perspectives on the same entity
age financialStatus
Retiree
Rich
98
Orthogonal Regions
Combine multiple simultaneous descriptions
age financialStatus
Retiree
Rich
Retiree
Rich
99
LawAbiding LawAbiding
Poor Poor
robBank/
robBank/
Outlaw Outlaw
Rich Rich
100
Catch22 Catch22
sanityStatus
Crazy Crazy
entry/sane := false; entry/sane := false;
Flying Flying
entry/flying := true; entry/flying := true;
(sane)/
Sane Sane
entry/sane := true; entry/sane := true;
Grounded Grounded
entry/flying := false; entry/flying := false;
101
Manager Manager
employee
102
Person1
Child
Person2
Child
Adult
Adult
Retiree
Retiree
103
Basic State Machine Concepts Statecharts and Objects Advanced Modeling Concepts Case Study Wrap Up
104
AB sender
line card 1
End user
. . .
AB receiver
AB receiver AB sender
SWITCH
End user
line card N
Behavioral Modeling with UML 105
Receiver
unpacker
data(1) data(1) ack ackA ack data(2) pktB data(2) ack ackB ack etc.
106
Receiver SM
RcvdPktA pktA/^data
107
Additional Considerations
Support (control) infrastructure
operator interface
System operator
SWITCH
DB interface
DBase
108
Control
The set of (additional) mechanisms and actions required to bring a system into the desired operational state and to maintain it in that state in the face of various planned and unplanned disruptions For software systems this includes:
system/component start-up and shut-down failure detection/reporting/recovery system administration, maintenance, and provisioning (on-line) software upgrade
Failed
WaitAckA
WaitAckB
Hardware Audit
ReadyToGo
Failed
Operational
Behavioral Modeling with UML 111
Exploiting Inheritance
Abstract control classes can capture the common
control behavior
AbstractController
Sender
Receiver
. . .
112
AbstractController
Sender
Operational
ReadyToGo
113
Basic State Machine Concepts Statecharts and Objects Advanced Modeling Concepts Case Study Wrap Up
114
statecharts
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
Behavioral Modeling
Part 1: Interactions and Collaborations Part 2: Statecharts Part 3: Activity Diagrams
Conrad Bock, Intellicorp bock@intellicorp.com
117
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.
Behavioral Modeling with UML 118
Control Flow
Each step is taken when the previous one finishes
regardless of whether inputs are available, accurate, or complete (pull). Emphasis is on order in which steps are taken.
Start Weather Info Analyze Weather Info Analyze Weather Info
119
Object/Data Flow
Each step is taken when all the required input
objects/data are available and only when all the inputs are available (push). Emphasis is on objects flowing between steps.
Design Product Design Product Procure Procure Materials Materials Acquire Capital Acquire Capital
State Machine
Each step is taken when events are
detected by the machine using inputs given by the event. Emphasis is on reacting to environment.
Ready To Start Ready To Start Coin Deposited Ready For Order Ready For Order Cancel Button Pressed Dispense Dispense Product Product Return Return Change Change
Selection Made
element names.
Activity graphs will become independent
Subactivity
(simple state and submachine state) except that ... ... transitions coming out of them are taken when the step is finished, rather than being triggered by a external event, ... ... and they support dynamic concurrency.
Behavioral Modeling with UML 123
Action (State)
Action
directly start another activity graph, like invoking an operation on an object, or running a userspecified action.
However, an action can invoke an operation that
124
Subactivity (State)
Subactivity
subactivity states.
Behavioral Modeling with UML 125
Example
POEmployee.sortMail Deliver Mail
Deliver Mail POEmployee sortMail() Check Out Truck Put Mail In Boxes
126
states invoke operations, and all activity graphs are methods for operations.
Behavioral Modeling with UML 127
Dynamic concurrency
Action/Subactivity Applies to actions and subactivities. Not inherited from state machines. Invokes an action or subactivity any number of times in
or how arguments are accessed by actions. Attach a note as workaround for expression. Issue for UML 1.4.
Behavioral Modeling with UML 128
Order [Taken]
Fill Order
Coordinating Steps
Inherited from state machines Initial state Final state Fork and join
131
Coordinating Steps
Decision point and merge (
Calculate Cost
Charge Account
Get Authorization
Behavioral Modeling with UML 132
Coordinating Steps
Synch state (
) is inherited from state machines but used mostly in activity graphs. Provides communication capability between parallel processes.
State machine notation
Build Frame Put On Roof Install Walls
Install Foundation
Inspect * *
133
composite states. Synch states may be omitted for the common case (unlimited bound and one incoming and outgoing transition).
Activity diagram notation
Build Frame Put On Roof Install Walls Inspect
Install Foundation
134
A 11
A 12
A 13
O bj [S 2]
A 21
A 22
A 23
135
Convenience Features
Fork transitions can have guards.
[ priority = 1]
Evaluate Impact
Evaluate Impact
Register Bug
[else]
Fix Bug
Convenience Features
Partitions are a grouping mechanism. Swimlanes are the notation for partitions. They do not provide domain-specific semantics. Tools can generate swimlane presentation from
Management
Revise Plan
Support
Register Bug Release Fix
Engineering
Fix Bug
Convenience Features
Signal send icon
Wake Up Signal
translates to a transition
Get Cups
Coffee Pot
Coffee Done
Drink Coffee
138
partition
Submission Team Task Force Revision Task Force
action state
control flow
Begin
initial state
fork of control
Case Study
Issue RFP
conditional fork
join of control
Submit specification draft [optional] Collaborate with competitive submitters Specification [initial proposal]
object flow
input value
Adapted from Kobryn, UML 2001 Communications of the ACM October 1999
139
Case Study
Vote to recommend
guard
Specification [adopted] [YES] [NO]
decision
Implement specification
Revise specification
Adapted from Kobryn, UML 2001 Communications of the ACM October 1999
[else]
[Enhanced]
final state
140
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).
141
control flow.
You can mix state machine and
control/object flow constructs on the same diagram (though you probably do not want to).
Behavioral Modeling with UML 142
Request Return Get Return Number Ship Item Receive Item Item [returned]
Restock Item
Credit Account
Item [available]
143
Customer
Telesales
Accounting
Warehouse
Item [returned]
Receive Item
Restock Item
Credit Account
Item [available]
144
composite states were there by matching all forks/decisions with a correspond join/merges one that is well-nested. machine semantics.
or check that the diagram can be translated to This insures that diagram is executable under state
145
146
147
148
rather than event-driven applications like embedded Activity diagrams are a kind of state machine until
so control and object/data flow do not have separate UML 1.3 has new features for business modeling that
149
Model management Standard elements and profiles Object Constraint Language (OCL)
150
Further Info
Web: OMG UML Resource Page
www.omg.org/uml/ www.omg.org/cgi-bin/doc?omg/99-11-04
Email Gunnar vergaard: gunnaro@it.kth.se Bran Selic: bran@objectime.com Conrad Bock: bock@intellicorp.com Conferences & workshops UML World 2000, NYC, March 00 UML 00, York, England, Oct. 00
Behavioral Modeling with UML 151