Вы находитесь на странице: 1из 15

Presented by:

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 .

o Formal language to express constraints,


that remains easy to read and write.
o Developed by IBM and standardized by OMG .
Integrated into the UML standard.

3
o To specify invariants on classes and types in the class model.

o To specify type invariants for stereotypes.

o To describe pre- and post-conditions on operations and

methods.

o As a navigation language.

o To specify constraints on operations.

o OCL is used to specify the well-formedness rules of the UML.

4
• Possible number of owners a car can have
 Required age of car owners

• Requirement that a person may own at most


one black car

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”:

context Person inv: self.fleet–>size <= 3

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

Вам также может понравиться