Object Constraint Language

The object constraint language was covered as part of the Software Engineering module (COM00144M) during my MSc studies with the University of York. This post will provide information on why OCL is used and examples of how you can implement OCL.

What is OCL?

The object constraint language (OCL) is a declarative ISO standard language created by IBM. OCL was developed to help relieve limitations with UML modelling and to allow the specification of more precise aspects of a system design. OCL is a part of the Unified Modelling Language (UML) set by the Object Management Group (OMG) as a standard for object-oriented design.

OCL is a declarative and side-effect free language which means the constraints only enforce rules, they do not assign values or modify the system.

Some usages of OCL include:

  • Invariants specify constraints that have to equal true during the instance of an objects lifetime
  • Preconditions specify constraints that have to equal true before a method is run
  • Postconditions specify constraints that have to equal true after a method is run
  • Initialisation specify default property values
Read More