examples of Object Constraint Language (OCL) expressions

0

OCL Is a formal language used to express constraints, that remains easy to read and write.

• Is a declarative language for describing rules that apply to Unified Modeling Language (UML).
 

All Contributions

  • The age of employees must be greater than or equal to 18

context Employee inv:  self.age() >=  18

 

  • The hire date of  employees must be greater than their birth  date

context Employee inv:  self.hireDate >  self.birthDate

 

  • The supervisor of an employee must be older than the employee

context Employee inv:

self.supervisor→ notEmpty() implies self.age() <  self.supervisor.age()

The condition notEmpty must be tested since the multiplicity of the role is not mandatory.

 

  • The salary of an employee cannot be greater than the salary of his/her supervisor

context Employee inv:

self.supervisor→ notEmpty() implies 

self.salary <  self.supervisor.salary

 
  • The start date of an employe as manager of a department must be greater than his/her hire date

context Employee inv:

self.manages→ notEmpty() implies self.manages.startDate > self.hireDate

 

  • The manager of a department must be an employee of the   department.

context Department inv:

self.worksFor→ includes(self.manages.employee)

 

  • An employee works at most in 4 projects

context Employee inv:

self.worksOn→ size() <= 4

 

  • An employee cannot supervise him/herself.

context Employee inv: 

self.subordinates →  excludes(self)

total contributions (1)

New to examplegeek.com?

Join us