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¶
Scenario 2¶
Scenario 3¶
Scenario 4¶
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.