OCUP2F 03 OCL
Jump to navigation
Jump to search
Module 3. Object Constraint Language⌘
References⌘
- OCL Specification Document (Version 2.0 or 2.2; Chapter 7 – All) http://www.omg.org/spec/OCL/
Object Constraint Language (OCL)⌘
- OMG Specification
- Object Constraint Language (OCL), a formal language used to describe expressions on UML models
Why OCL?⌘
- A UML diagram is typically not refined enough to provide all the relevant aspects of a specification.
- There is a need to describe additional constraints about the objects in the model.
- Such constraints are often described in natural language. Practice has shown that this will always result in ambiguities.
- OCL is a formal language that has been developed to fill this gap.
- OCL expressions do not have side effects (i.e., their evaluation cannot alter the state of the corresponding system).
Class Diagram Example⌘
Context⌘
Context of an OCL expression within a UML model can be specified through:
- context declaration:
context Company
self.numberOfEmployees > 50
- in a diagram, with dashed lines to connect it to its contextual element
Invariants⌘
- Invariant is OCL expression that must be true for all instances of a classifier at any time.
context Company inv:
self.numberOfEmployees > 50
Pre- and Postconditions⌘
context Typename::operationName(param1 : Type1, ... ): ReturnType
pre : param1 > ...
post: result = ...
context Company inv:
self.numberOfEmployees > 50
Invariants⌘
context Company inv:
self.numberOfEmployees > 50
context Company inv enoughEmployees:
self.numberOfEmployees > 50
Invariants⌘
context Company inv:
self.numberOfEmployees > 50
Invariants⌘
context Company inv:
self.numberOfEmployees > 50