introduction to ocl - kitbeckert/teaching/verification-ss06/10... · ocl object constraint language...
TRANSCRIPT
![Page 1: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/1.jpg)
Introduction to OCL
Bernhard Beckert
UNIVERSITÄT KOBLENZ-LANDAU
– p.1
![Page 2: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/2.jpg)
OCL
Object Constraint Language
• Part of the UML standard.
• Formal Specification Language. Precise semantics.
• (Quite) easy to read syntax.
• Why? Because UML is not enough!
– p.2
![Page 3: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/3.jpg)
OCL
Object Constraint Language
• Part of the UML standard.
• Formal Specification Language. Precise semantics.
• (Quite) easy to read syntax.
• Why? Because UML is not enough!
– p.2
![Page 4: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/4.jpg)
OCL
Object Constraint Language
• Part of the UML standard.
• Formal Specification Language. Precise semantics.
• (Quite) easy to read syntax.
• Why? Because UML is not enough!
– p.2
![Page 5: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/5.jpg)
OCL
Object Constraint Language
• Part of the UML standard.
• Formal Specification Language. Precise semantics.
• (Quite) easy to read syntax.
• Why? Because UML is not enough!
– p.2
![Page 6: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/6.jpg)
UML is not enough. . .
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
• Possible number of owners a car can have
• Required age of car owners
• Requirement that a person may own at most one black car
– p.3
![Page 7: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/7.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:
context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 8: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/8.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 9: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/9.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 10: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/10.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 11: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/11.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 12: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/12.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 13: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/13.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
What does this mean, instead?context Personinv: self.age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 14: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/14.jpg)
Some OCL examples I
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“A vehicle owner must be at least 18 years old”:context Vehicleinv: self. owner. age >= 18
“A car owner must be at least 18 years old”:context Carinv: self.owner.age >= 18
– p.4
![Page 15: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/15.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“Nobody has more than 3 vehicles”:
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 16: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/16.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“Nobody has more than 3 vehicles”:context Personinv: self.fleet–>size <= 3
or change multiplicity
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 17: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/17.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 18: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/18.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 19: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/19.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:
context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 20: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/20.jpg)
Some OCL examples II
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
“All cars of a person are black”:
context Personinv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
– p.5
![Page 21: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/21.jpg)
Some OCL examples III — iterate
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
What does this mean?context Personinv: self.fleet–>iterate(v; acc:Integer=0
| if (v.colour=#black)then acc + 1 else acc endif) <=3
– p.6
![Page 22: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/22.jpg)
Some OCL examples IV — oclIsKindOf
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Personinv: age<18 implies self.fleet–>forAll(v | not v.oclIsKindOf(Car))
“A person younger than 18 owns no cars.”
“self” can be omitted.
Logical Junctors: and, or, not, implies, if. . . then. . . else. . . endif, =
– p.7
![Page 23: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/23.jpg)
Some OCL examples IV — oclIsKindOf
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Personinv: age<18 implies self.fleet–>forAll(v | not v.oclIsKindOf(Car))
“A person younger than 18 owns no cars.”
“self” can be omitted.
Logical Junctors: and, or, not, implies, if. . . then. . . else. . . endif, =
– p.7
![Page 24: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/24.jpg)
Some OCL examples IV — oclIsKindOf
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Personinv: age<18 implies self.fleet–>forAll(v | not v.oclIsKindOf(Car))
“A person younger than 18 owns no cars.”
“self” can be omitted.
Logical Junctors: and, or, not, implies, if. . . then. . . else. . . endif, =
– p.7
![Page 25: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/25.jpg)
Some OCL examples IV — oclIsKindOf
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Personinv: age<18 implies self.fleet–>forAll(v | not v.oclIsKindOf(Car))
“A person younger than 18 owns no cars.”
“self” can be omitted.
Logical Junctors: and, or, not, implies, if. . . then. . . else. . . endif, =
– p.7
![Page 26: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/26.jpg)
Some OCL examples V — allInstances
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Carinv: Car.allInstances()->exists(c | c.colour=#red)
“There is a red car.”
– p.8
![Page 27: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/27.jpg)
Some OCL examples V — allInstances
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
context Carinv: Car.allInstances()->exists(c | c.colour=#red)
“There is a red car.”
– p.8
![Page 28: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/28.jpg)
OCL pre-/post conditions — Examples
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
So far only considered class invariants.
OCL can also specify operations:
“Calling getName() delivers the value of the attribute name.”
context Person::getName()post: result = name
– p.9
![Page 29: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/29.jpg)
OCL pre-/post conditions — Examples
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
So far only considered class invariants.
OCL can also specify operations:
“Calling getName() delivers the value of the attribute name.”
context Person::getName()post: result = name
– p.9
![Page 30: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/30.jpg)
OCL pre-/post conditions — Examples
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
So far only considered class invariants.
OCL can also specify operations:
“If setAge(. . . ) is called with a non-negative argument then the
argument becomes the new value of the attribute age.”
context Person::setAge(newAge:int)pre: newAge >= 0post: self.age = newAge
“Calling getName() delivers the value of the attribute name.”
context Person::getName()post: result = name
– p.9
![Page 31: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/31.jpg)
OCL pre-/post conditions — Examples
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
So far only considered class invariants.
OCL can also specify operations:
“Calling birthday() increments the age of a person by 1.”
context Person::birthday()post: self.age = self.age@pre + 1
“Calling getName() delivers the value of the attribute name.”
context Person::getName()post: result = name
– p.9
![Page 32: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/32.jpg)
OCL pre-/post conditions — Examples
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
So far only considered class invariants.
OCL can also specify operations:
“Calling getName() delivers the value of the attribute name.”
context Person::getName()post: result = name
– p.9
![Page 33: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/33.jpg)
Queries
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
Special to OCL are operations with a �query� stereotype:
Only these operations can be used within an OCL expression.
“Calling getName() delivers the value of the attribute name.”
context Personinv: self.getName() = name
– p.10
![Page 34: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/34.jpg)
Queries
Person
name:String
age:int
�query�
getName():String
birthday()
setAge(newAge:int):int
Vehicle
colour:Colour
�enumeration�
Colour
black():Colour
white():Colour
red():Colour
Car Bike
1 0..*
ownershipowner fleet
Special to OCL are operations with a �query� stereotype:
Only these operations can be used within an OCL expression.
“Calling getName() delivers the value of the attribute name.”
context Personinv: self.getName() = name
– p.10
![Page 35: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/35.jpg)
OCL Basics
• OCL is used to specify invariants of objects and
pre- and post conditions of operations. Makes UML (class)
diagrams more precise.
• OCL expressions use vocabulary of UML class diagram.
• OCL attribute accesses “navigate” through UML class diagram.
• “context” specifies about which elements we are talking.
• “self” indicates the current object. “result” the return value.
– p.11
![Page 36: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/36.jpg)
OCL Basics
• OCL is used to specify invariants of objects and
pre- and post conditions of operations. Makes UML (class)
diagrams more precise.
• OCL expressions use vocabulary of UML class diagram.
• OCL attribute accesses “navigate” through UML class diagram.
• “context” specifies about which elements we are talking.
• “self” indicates the current object. “result” the return value.
– p.11
![Page 37: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/37.jpg)
OCL Basics
• OCL is used to specify invariants of objects and
pre- and post conditions of operations. Makes UML (class)
diagrams more precise.
• OCL expressions use vocabulary of UML class diagram.
• OCL attribute accesses “navigate” through UML class diagram.
• “context” specifies about which elements we are talking.
• “self” indicates the current object. “result” the return value.
– p.11
![Page 38: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/38.jpg)
OCL Basics
• OCL is used to specify invariants of objects and
pre- and post conditions of operations. Makes UML (class)
diagrams more precise.
• OCL expressions use vocabulary of UML class diagram.
• OCL attribute accesses “navigate” through UML class diagram.
• “context” specifies about which elements we are talking.
• “self” indicates the current object. “result” the return value.
– p.11
![Page 39: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/39.jpg)
OCL Basics
• OCL is used to specify invariants of objects and
pre- and post conditions of operations. Makes UML (class)
diagrams more precise.
• OCL expressions use vocabulary of UML class diagram.
• OCL attribute accesses “navigate” through UML class diagram.
• “context” specifies about which elements we are talking.
• “self” indicates the current object. “result” the return value.
– p.11
![Page 40: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/40.jpg)
OCL Basics (cont.)
• OCL can talk about collections (here: sets).
Operations on collections: –>
Example operations: select, forAll, iterate
• “iterate” can simulate all other operations on collections.
• Queries (= side-effect-free operations) can be used in OCL
expressions.
• In operations, “. . . @pre” refers to the pre-state of an attribute or
query.
– p.12
![Page 41: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/41.jpg)
OCL Basics (cont.)
• OCL can talk about collections (here: sets).
Operations on collections: –>
Example operations: select, forAll, iterate
• “iterate” can simulate all other operations on collections.
• Queries (= side-effect-free operations) can be used in OCL
expressions.
• In operations, “. . . @pre” refers to the pre-state of an attribute or
query.
– p.12
![Page 42: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/42.jpg)
OCL Basics (cont.)
• OCL can talk about collections (here: sets).
Operations on collections: –>
Example operations: select, forAll, iterate
• “iterate” can simulate all other operations on collections.
• Queries (= side-effect-free operations) can be used in OCL
expressions.
• In operations, “. . . @pre” refers to the pre-state of an attribute or
query.
– p.12
![Page 43: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/43.jpg)
OCL in TogetherCC/KeY
TogetherCC cannot process OCL constraints. It is however possible to
specify textual invariants and pre- and post conditions.
With the KeY extensions to TogetherCC syntax (type) checks of OCL
constraints are possible.
– p.13
![Page 44: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/44.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 45: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/45.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 46: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/46.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18
�context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 47: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/47.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �
context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 48: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/48.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black)
4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 49: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/49.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4
context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 50: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/50.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3
�inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 51: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/51.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �
inv: Car.allInstances()–>exists(c | c.colour=#red) 4
– p.14
![Page 52: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/52.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red)
4
– p.14
![Page 53: Introduction to OCL - KITbeckert/teaching/Verification-SS06/10... · OCL Object Constraint Language Part of the UML standard. Formal Specication Language. Precise semantics. (Quite)](https://reader031.vdocuments.us/reader031/viewer/2022021612/5b9c985309d3f29b498cf629/html5/thumbnails/53.jpg)
System state
id0815:Person
name = ‘‘Jane’’
age = 5
harley17:Bike
colour = idBlack
idBlack:Colour
black() = idBlack
white() = idWhite
red() = idRed
id0825:Person
name = ‘‘Paul’’
age = 25
bmw3:Car
colour = idWhite
idWhite:Colour
black() = idBlack
white() = idWhite
red() = idRed
idRed:Colour
black() = idBlack
white() = idWhite
red() = idRed
ownership
ownership
context Vehicleinv: self.owner.age >= 18 �context Personinv: self.fleet–>forAll(v | v.colour = #black) 4context Personinv: self.fleet–>select(v | v.colour = #black)–>size <= 3 �inv: Car.allInstances()–>exists(c | c.colour=#red) 4 – p.14