Академический Документы
Профессиональный Документы
Культура Документы
M.Noman
Maham Tahir
Rizwan
1
OCL stands for Object Constraint Language.
2
o The Object Constraint Language (OCL) is
a declarative language describing rules applying
to Unified Modeling Language .
3
o To specify invariants on classes and types in the class model.
methods.
o As a navigation language.
4
• Possible number of owners a car can have
Required age of car owners
5
“A vehicle owner must be at least 18 years old”:
6
“A vehicle owner must be at least 18 years
old”:
context Vehicle inv: self. owner. age >= 18
7
“A vehicle owner must be at least 18 years old”:
context Vehicle
inv: self. owner. age >= 18
What does this mean, instead?
context Person inv: self.age >= 18
8
“All cars of a person are black”:
9
context Person
inv: self.fleet–>forAll(v | v.colour = #black)
“Nobody has more than 3 black vehicles”:
10
Nobody has more than 3 black vehicles”:
11
context Car inv: Car.allInstances()->exists(c |
c.colour=#red)
“There is a red car.”
12
So far only considered class invariants. OCL
can also specify operations
attribute age.” context
Person::setAge(newAge:int)
pre: newAge >= 0
post: self.age = newAge
13
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
14
Thank You
15