Documente Academic
Documente Profesional
Documente Cultură
82
Overview
What are constraints
Core OCL Concepts
Advanced OCL Concepts
Wrap up
83
Use the
Object
Constraint
Language
84
Thats why !!
Flight
PassengerFlight
flights
0..*
CargoFlight
Airplane
0..*
0..*
1
PasssengerPlane
CargoPlane
85
Flight
type =
enum{cargo, passenger}
0..*
flights
Airplane
type =
enum{cargo, passenger}
context Flight
inv: type = #cargo implies airplane.type = #cargo
inv: type = #passenger implies airplane.type = #passenger
86
Definition of constraint
A constraint is a restriction on one or more
87
Precondition of an operation
Postcondition of an operation
88
Constraint stereotypes
UML defines three standard stereotypes for
constraints:
invariant
precondition
postcondition
89
What is OCL?
OCL is
unambiguous
no side effects
90
model
91
Overview
What are constraints
Core OCL Concepts
Advanced OCL Concepts
Wrap up
92
Example model
Flight
Airport
origin
name: String
destination
departing
Flights
departTime: Time
*
/arrivalTime: Time
duration : Interval
*
maxNrPassengers: Integer
flights
airline
arriving
Flights
Airline
passengers
* {ordered}
name: String
Passenger
$minAge: Integer
age: Integer
needsAssistance: Boolean
0..1
book(f : Flight)
CEO
airline
0..1
93
context.
The context may be denoted within the
expression using the keyword self. Who?
Me?
94
Notation
Constraints may be denoted within the UML
the expression:
context Flight inv: self.duration < 4
is identical to:
context Flight inv: duration < 4
is identical to:
Flight
<<invariant>>
duration < 4
duration: Integer
95
used:
basic types: String, Boolean, Integer, Real.
classifiers from the UML model and their features
96
97
98
Interval
nrOfDays : Integer
nrOfHours : Integer
nrOfMinutes : Integer
equals(i:Interval):Boolean
$Interval(d, h, m : Integer) :
Interval
99
starting point.
Role names are used to identify the
navigated association.
100
Example: navigations
Navigations
context Flight
inv: origin <> destination
inv: origin.name = Amsterdam
context Flight
inv: airline.name = KLM
101
Association classes
context Person inv:
if employer.name = Klasse Objecten then
job.type = #trainer
else
job.type = #programmer
endif
Job
type : {trainer, programmer}
Person
*
employee
1
employer
Company
name : String
102
Collections
103
Bag:
Sequence:
104
Collection operations
OCL has a great number of predefined
Syntax:
collection->operation
105
106
airp1
f1
airline1
f2
f3
airp2
airline2
f4
airline3
f5
departing flights
arriving flights
Advanced Modeling with UML
107
collection->select(elem : T | expression)
collection->select(elem | expression)
collection->select(expression)
The select operation results in the subset of all
108
f2
duration = 5
f3
duration = 3
airp2
f4
duration = 5
airline1
airline2
airline3
f5
duration = 2
departing flights
arriving flights
Advanced Modeling with UML
109
collection->forAll(elem : T | expr)
collection->forAll(elem | expr)
collection->forAll(expr)
The forAll operation results in
110
f2
depart = 5
f3
depart = 8
airp2
f4
depart = 9
airline1
airline2
airline3
f5
depart = 8
departing flights
arriving flights
Advanced Modeling with UML
111
collection->exists(elem : T | expr)
collection->exists(elem | expr)
collection->exists(expr)
The exists operation results in
112
f2
depart = 5
f3
depart = 8
airp2
f4
depart = 9
airline1
airline2
airline3
f5
depart = 8
departing flights
arriving flights
Advanced Modeling with UML
113
114
element
size: number of elements in collection
count(elem): number of occurences of elem in
collection
includes(elem): true if elem is in collection
excludes(elem): true if elem is not in collection
includesAll(coll): true if all elements of coll are
in collection
Advanced Modeling with UML
115
Result in postcondition
Example pre and postcondition
116
closed
open
context Bottle inv:
self.oclInState(closed) implies filled = #full
117
Local variables
The Let construct defines variables local to one
constraint:
Let var : Type = <expression1> in <expression2>
118
Iterate
The iterate operation for collections is the most
119
Iterate example
Example iterate:
context Airline inv:
flights->select(maxNrPassengers > 150)->notEmpty
Is identical to:
context Airline inv:
flights->iterate(f : Flight; answer : Set(Flight) = Set{ } |
if f.maxNrPassengers > 150 then
answer->including(f)
else answer endif )->notEmpty
120
Inheritance of constraints
Guiding principle Liskovs Substitution Principle
(LSP):
121
Inheritance of constraints
Consequences of LSP for invariants:
postconditions:
A precondition may be weakened
A postcondition may be strengthened
122
Wrap up
What are constraints
Core OCL Concepts
Advanced OCL Concepts
Wrap up
123
Current Developments
Feedback from several OCL implementors
handled in UML-RTF
e.g. the grammar has some loose ends
typical tool-related issues
formalization of OCL
Advanced Modeling with UML
124
OCL Tools
Cybernetics
ww.cybernetic.org
University of Dresden
www-st.inf.tu-dresden.de/ocl/
Boldsoft
www.boldsoft.com
ICON computing
www.iconcomp.com
Royal Dutch Navy
Others
Advanced Modeling with UML
125
126