Exercise 01: Advanced UML - OCL Constraints

Goals of this exercise

OCL stands for Object Constraint Language. In this exercise, you will write OCL constraints for scenarios described in UML at the end of Lecture 01.

At the end of the exercise you will be familiar with the syntax of OCL and learn to formulate constraints from given conditions. This exercise will also be your first hands-on experience with the UML Modelling Software ‘Enterprise Architect’. The documentation to get yourselves familiarised with the interface was already shared but can also be found here in Enterprise Architect

Important

Enterprise Architect is only a recommendation for this exercise to get some hand-on experience od the software’s user interface. It is not mandatory and students are welcome to construct OCL constrains in doc/powerpoint/notepad or by hand. The submission can be any type of file including .eap, .pdf, .doc. .txt or even a photograph of a handwritten solution.

Note

  • If you would like to do this exercise in Enterprise Architect, a sample .QEA file has been provided here in the Data Repository and also on Moodle under Exercise 01

  • Please create a separate ‘package’ for each scenario to avoid confusion.

Recap from the Lecture on OCL

  • OCL uses invariants to specify constraints on objects in order to ensure a consistent state of the model (w.r.t the modelled reality)

  • Invariant (in OCL): An invariant is a constraint that states a condition that must always be met by the object the invariant is associated with

    • Invariants are described using Boolean expressions

    • The Boolean expression must evaluate to true if the invariant is met

    • Invariants must be true all the time

General Syntax for OCL constraints.

context <ClassName> inv: <OCL-expression>
Syntax for OCL constraints with pre/post conditions.

context <ClassName::operationName(param1:Type1, …)> : ReturnType
pre: <OCL-expression>
post: <OCL-expression>

More Information on OCL

  • For an overview on OCL syntax, and common OCL structuring please see the slides from 41 to 53 of Lecture 01

  • Slide 53 contains a list of common Boolean functions used in OCL constraint

Exercise Tasks

You will be given the UML Model file (in .qea format) for Scenario 1 in the Data Repository and also in Moodle under ‘Exercise 1’ for those that have not activated their Microsoft Accounts yet. You are expected to build multiple class diagrams describing each of the following in the same same project.

Build Class Diagrams and describe OCL constraints for each of the following scenarios based on the given conditions.

Scenario 1

../_images/image1.png
  1. The area of a parcel may not be zero or negative.

  2. Roads (usage = traffic) must be owned by the municipality.

Scenario 2

../_images/image2.png
  1. Roads (usage = traffic) must be owned by the municipality

  2. Construction sites (usage = site) must be adjacent to a road (usage = traffic)

Scenario 3

../_images/image3.png
  1. Parcels containing buildings must be adjacent to a road (usage = traffic)

  2. Parcels containing buildings and having a minimum area of 500 m2 must be adjacent to a road (usage = traffic)

Scenario 4

../_images/image4.png
  1. A CSO is either represented by at least one BSO or a CSO contains at least one other CSO.

  2. One CSO is related to at least one CSO/BSO, but that same CSO is not related to CSOs and BSOs at the same time.

Submission

The Submission is due on Monday, 19. May 2025. The submission link can be found in Moodle here

Please take note!

Submit the OCL constraints in Class Diagrams for the above scenarios as a single .qea file having multiple packages with class diagrams (OR) as a screenshot image, .pdf, .doc, .txt etc. The medium of submission is not restricted.