Re: asking about OCL



Re: asking about OCL

From: Frédéric FONDEMENT <frederic.fondement_at_epfl.ch>
Date: Wed, 17 May 2006 08:31:13 +0200
Message-ID: <446AC331.8020903@epfl.ch>
Hello all,

Just a naive question (and the start point for another interesting debate ?)

If Ajaree places in his MODEL

context A
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" 
expression.

A::allInstances()->forAll(A::allInstances()->notEmpty())


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

context ModelElement
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.

Frédéric Fondement

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