Re: asking about OCL
Just a naive question (and the start point for another interesting debate ?)
If Ajaree places in his MODEL
inv testExistence: A::allInstances()->notEmpty() --or anything equivalent
I guess this will not solve his very first problem which is: there must
have an element of kind A in his model.
Indeed, the previous expression is equivalent to the "contextless"
That means if there is no instance of A in the model, then the
expression testExistence is never evaluated, so it cannot trigger any
problem. If there are n instances of A, then, the expression
testExistence is evaluated n times to false, which is not that necessary.
Now, if he places in his metamodel
context ModelElement -- context A would be an error here since A is not
part of the meta-metamodel which is MOF
inv testExistenceMMa: A::allInstances()->notEmpty()
Will A really be identified with the model element whose name is A ??? I
guess no. Then, let Ajaree write
inv testEcistenceMMb: self.qualifiedName = "PathForA::A" implies
self.allInstances()->notEmpty() -- not that elegant, is it ?
Now, it should solve Ajaree's problem, but again, there is a problem of
evaluation. If evaluated on a model, then the expression will be
considered as ill-formed (ModelElement is NOT part of the metamodel). If
evaluated on the metamodel, then the expression will always return
false, because A is still not instanciated. Let's now imagine that there
are some instanciating models (only one is just a very special case, but
if one writes a metamodel, it is certainly not just to instanciate one
model), then which one to take to evaluate allInstances(). So the
expression should be evaluated on the metamodel given one model, which
is not my understanding of OCL at metamodel level (maybe am I wrong).
As a conclusion, I would say that there are two annoying problems in OCL
there, that I have also encountered wring my metamodels (on UML, I use
to place such expressions with the Model metaclass context).
1 - How to place a "contextless" OCL expression.
2 - How to place a model-level OCL expression wich is mandatory for any
model at the metamodel level.
A::allInstances()->notEmpty() is rather elegant and human-readable, but
if false to my belief because it has to have a context, and because is
should be evaluated on any model, and not the metamodel level.
PS: Ajaree's problem exists in UML: how to state in UML that there must
have one and only one Model instance ?
Received on Wed 17 May 2006 - 07:31:52 BST