Object Constraint Language (OCL)#

This example present defining the OCL constraints on the model. Lets take an example of model containing libraries, books and authors. The UML diagram is depicted in the following figure.

Library model

We can set a rule that says every book must have more than zero pages. To do this, we use the following constraint:

context Book: self.pages > 0

Note

B-OCL Interpreter is available at https://github.com/BESSER-PEARL/B-OCL-Interpreter. With this interpreter you can validate your OCL constraints defined on B-UML models.