The Object Constraint Language OCL

OCL is a side-effect free, pure expression language originally developed by IBM. Later, OCL was incorporated into the UML specification by OMG. OCL expressions return values, but they cannot be used to alter the model in any way. There are three aspects of working with OCL in Delphi 8 for .NET:

  • Setting invariant constraints. OCL expressions are used at designtime to set restrictions on attributes and properties of classes. For example, you can specify that the Social Security attribute of an Employee class cannot be set to null. You can then use the ECO framework to enforce this constraint at runtime.
  • Creating derived associations and attribute values. Derived associations and attribute values are computed from other elements. OCL expressions are used to specify how this computation is carried out. Derived elements avoid redundancy, but perhaps even more important, they allow you to specify business rules in one place, rather than in multiple places in source code.
  • Navigating associations on the class diagram. You can use OCL as a query language, to return collections of objects in your ECO Space. You can then use these collections directly in .NET data-aware controls to display and edit the values. For example, the following OCL statement Person. allinstances.birthDate retrieves a collection of the values of the birthDate attribute for all instances of the Person class. OCL's querying capabilities not only apply to class properties and attributes, but to associations you have defined on the class diagram. For example, say you have a Person class, and it has an association end called "Home", of type Building, and Building has an attribute called Address. When you evaluate the OCL expression Home.Address in the context of a specific Person object, you will get back the value of the Address attribute of the instance of Home associated with that Person.
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment