This is not directly an answer to your question, but hopefully would provide more insight regarding the question you are asking:
if an object (say an instance of Man) has no link (say address) to another object (say instance of Address), traversing self.address
with self being a Man, would be undefined at all for the self! (Note that address is a reference and Address is a type).
It seems that oclIsUndefined()
operation can be used for this purpose (as gefei mentioned), So probably self.address -> oclIsUndefined()
would work for you!
Page 16 of the OCL specification says:
... there is an explicit operation for testing if the value of an
expression is undefined. oclIsUndefined() is an operation on OclAny
that results in True if its argument is null or invalid and False
otherwise.
But there is another perspective:
self.address
represents a collection. So isEmpty
function should return true if it is empty! (This is the way you probably think to come to using self.address->isEmpty
)
Page 175 of the OCL specification regarding isEmpty function says:
isEmpty() : Boolean
Is self the empty collection?
post: result = (self->size() = 0 )
Note: null->isEmpty() returns 'true' in virtue of
the implicit casting from null to Bag{}
But as you mentioned isEmpty was not working for you!
I am leaving this to OCL experts to comment the difference? But probably the first approach would help!
Hope this helps!