I just recently started to look deeper into the intricacies of OCL. During my first applications, the following question came up:
Is it possible, and if so, what is the correct way to derive an attribute in case that no value is provided?
Approaches that came to my mind, but which may be formally incorrect were:
context GenericClass::genericAttribute : PrimitiveType
derive: if genericAttribute.oclIsUndefined() then
<expression of matching type>
endif
Another approach I could think of was
context GenericClass::genericAttribute : PrimitiveType
inv: genericAttribute.oclIsUndefined implies genericAttribute = <expression of matching type>
Admittedly, both approaches appear to be a bit awkward and thus I'd be happy if you could show me the formally correct way.