Does anyone know a good tutorial on object restriction language (OCL)?

I came across two questions about OCL expressions. After reading some university slides and googling, I still can't get it right.

I wonder if you know that any of you know the good resources that I have to read in order to understand this.


Limitations that concern me:

  • Everyone who works in the department has the same manager.
  • No one in the company is a manager.
  • No one in the company earns more than his manager.

For the first I have:

context department

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

Second:

context Company

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

Third:

context Company

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

but I donโ€™t think it is right. I am not sure whether in examples 2 and 3 I really compare individual employees with their actual manager / manager salary.

+6
constraints modeling uml
source share
4 answers

Quick solution to restrictions:

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)

By the way, I really don't see the need for a company class (how many company type objects do you have in the system?). If the restrictions for two companies are true for all companies, then they can be expressed using Person as a context in this way (for example, with number 2): context Person inv: self.manager <> self)

We can also add checks to make sure that the employee has a manager before performing the comparison

+2
source share

Finally, it turned out something good!

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

Object Restriction Specification

I like to answer my questions :)

+5
source share

For beginners, I would recommend this book: Object Restriction Language: Preparing Your Models for MDA Jos Warmer and Anneke Kleppe (Jos was one of the main creators of OCL).

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

I also really like the official specification that you have already found (especially the chapter offering an unofficial description of the language).

+4
source share

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

+3
source share

All Articles