7

I came across couple of questions about OCL expressions. After reading some university slides and googling it I still cannot properly understand it.

I wonder if any of you guys know any good resources that I should read to understand this stuff.


Constraints that bother me:

  1. Everybody working in the department has the same manager.
  2. Nobody in the company is the manager of him/herself.
  3. Nobody in the company earns more than his manager.

For the 1st one I have:

context Department

inv self.stuff -> forAll(manager = self.staff.manager)

2nd one:

context Company

inv self.employee -> select(manager = manager.manager) -> isEmpty()

3rd one:

context Company

inv self.employee -> select(salary > manager.salary) -> isEmpty()

but I dont think these are right. What I'm most unsure of is whether in example 2 and 3 I actually compare individual employees with theirs actual manager / manager salary.

user
  • 5,335
  • 7
  • 47
  • 63
Artur
  • 3,284
  • 2
  • 29
  • 35

4 Answers4

5

Finally got something good!

This is very informative document (PDF) from Object Management Group (OMG):

Object Constraint Language Specification

I love answering my own questions :)

Artur
  • 3,284
  • 2
  • 29
  • 35
4

The link to PDF file posted by @Artur has changed, Here is new link http://www.omg.org/spec/OCL/2.0/PDF/

Manu
  • 453
  • 2
  • 6
  • 15
4

For beginners I would recommend this book:The Object Constraint Language: Getting Your Models Ready for MDA by Jos Warmer and Anneke Kleppe (Jos was one of the main creators of the OCL).

There is also this free OCL tutorial (pdf + slides)

I also like a lot the official specification you already found (specially the chapter offering an informal description of the language).

Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
3

A quick solution on the constraints:

context Department inv: self.staff -> forAll(s1,s2| s1.manager = s2.manager)

context Company inv: self.employee->forAll(e| e.manager<>e)

context Company inv: self.employee->forAll(e| e.salary<=e.manager.salary)

Btw, I don't really see the need for the Company class (how many objects of type company do you have in the system?). If constraints two and three are true for all companies then they could be expressed using Person as context in this way (e.g. with number 2): context Person inv: self.manager<>self)

We can also add checks to see if the employee has a manager before doing the comparison

Jordi Cabot
  • 8,058
  • 2
  • 33
  • 39
  • It's not actual system. It's one of the revision questions for the exam :) I was wandering myself why there is Company class... Many thanks for your help. – Artur May 23 '09 at 23:15