Re: asking about OCL

Re: asking about OCL

From: Steffen Zschaler <>
Date: Wed, 17 May 2006 10:11:50 +0200
Message-ID: <>

That's a very good question indeed. I think, what you are saying is that 
the 'inv' context is not well chosen for this kind of constraint, 
because it always has the implicit all-quantification.

However, historically, the OCL specification really only talks about 
syntax and semantics. Pragmatics is covered in Chapt. 12 "The Use of OCL 
Expressions in UML Models", but at least to my understanding, this was 
never meant to be an exhaustive listing. So, I guess you could define a 
new 'context' in a manner very similar to that of Chapt. 12. You could 
make the contextualClassifier undefined, which would essentially forbid 
the use of 'self' in the OCL expression. And you could define that there 
is no implicit all-quantification.

Best regards,


Frédéric FONDEMENT wrote:
> 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 ?
> To remove yourself from this list please mail 
> with a message containing the word "unsubscribe".

Dipl.-Inf. Steffen Zschaler
Research Assistant

Technische Universität Dresden
Department of Computer Science

Phone +49 351 463 38555
Fax   +49 351 463 38459
Received on Wed 17 May 2006 - 09:11:54 BST