I am having a bit of troubles trying to understand the semantics of OCL operands in the OCL specification of version 2.4. In particular, to begin with, given a contextual model as a Student class, in which the available attributes is his age, then consider the current instance of this model includes the assignment of variable object is a student whose age is undefined
. I would like to ask what would the return value be when evaluating these the following examples:
Basically, I would like to understand the semantics of these operands in the presence of an undefined
value.
Thanks everyone!
There is no such concept as undefined in OCL 2.x. The vague OCL 1.x undefined concept evolved to null (not initialized) and invalid (bad).
In all your cases, use of the invalid value is not computable and so the result is invalid. In simple terms, a crash crashes.
Use of a null value compares to (another) null as true, but as false otherwise. In simple terms null is just another value that compares for equality as you might expect.
Relative comparisons of null are of course invalid.
The relevant OCL 2.4. specification sections are 11.2.4 and 11.3.2.
If you really want to understand how OCL handles computation failures, you may find [1] helpful .
[1] http://www.eclipse.org/modeling/mdt/ocl/docs/publications/OCL2021Validity/OCLValidity.pdf