Professional Documents
Culture Documents
SEG4110 - Advanced Software Engineering and Reengineering: Topic E Object Constraint Language (OCL)
SEG4110 - Advanced Software Engineering and Reengineering: Topic E Object Constraint Language (OCL)
SEG4110 - Advanced Software Engineering and Reengineering: Topic E Object Constraint Language (OCL)
TOPIC E
Object Constraint Language
(OCL)
What is OCL?
OCL is a formal language used to express
constraints.
Constraint:
• An invariant condition that must hold for the system being
modeled.
-- this is a comment
If D has attribute b
• Then the expression self.assoc.b evaluates to the
set of all the b’s belonging to D
context Company
inv: self.manager.isUnemployed = false
-- self.manager evaluates to a Person
inv: self.employee->notEmpty()
-- self.employee evaluates to a Set
aCollection->exists(booleanExpression)
• Returns true if booleanExpression is true for any
element of aCollection
• This is the equivalent of the symbol in
mathematical logic
self.employee->collect(birthdate)
• numberOfEmployees > 50
• self.numberOfEmployees > 50
context Typename::operationName(
param1 : Integer ): Integer
pre parameterOk: param1 > 5
post resultOk: result < 0
e.g.
context Company::hireEmployee(p : Person)
pre : not employee->includes(p)
post: employee->includes(p) and
stockprice() = stockprice@pre() + 10