EmPowerTec Logo

The Object Constraint Language

The Object Constraint Language (OCL) is an expression language that can be used to define expressions in object oriented models, in particular UML models. These expressions enrich the respective model with precise and unambiguous annotations, thus preserving precious information about the underlying business domain. With OCL you can complement the standard elements of UML, diagrams and use cases, with a third means that adds significant expressive power: a formal language.

Diagrams Use Cases Formal language

Ultimately, the OCL helps you to create rich and precise models, thus improving the productivity in your software development projects.

OCL-expressions can be used with various meanings:

  • Constraints are the most prominent use.
  • Initialization expressions can be used to specify an initial value for an attribute or an association.
  • OCL expressions can be used to specify the algorithm that is to be used for derived attributes, i.e. values that are calculated from other attributes or associations.
  • OCL expressions can be used to specify the implementation of methods as long as they do not have side effects (i.e. the method is 'read only').

A constraint defines a restriction on a systems state. In OCL, a constraint is an expression that always evaluates to true or false. If the constraint evaluates to false it is violated and the system is in an invalid state.
Constraints can be divided in three categories:

  1. invariants
    These conditions have to be TRUE always.
  2. preconditions
    These conditions have to be TRUE before the execution of a method starts.
  3. postconditions
    These conditions have to be TRUE after the execution of a method has finished.

In contrast to various other specification languages, OCL was designed to be easy to write and read, thus enabling business analysts and programmers to communicate effectively. Its syntax is similar to popular object oriented programming languages so that only few additional training is necessary to use it effectively. Since OCL is part of the UML standard defined by the OMG, your investment in OCL will be protected in the future.