Re: OCL expression



Re: OCL expression

From: Thomas Baar <thomas.baar_at_epfl.ch>
Date: Mon, 18 Dec 2006 18:15:14 +0100
Message-ID: <4586CCA2.8020207@epfl.ch>
Dear all,

Waldin, Earl wrote:

>
>constraint as
>  
>
>>"class A can not have any subclass"
>>
>>How can I express this constraint between: 
>> 
>>1. context A inv: self.inheritedMember->isempty()
>>
>>2. context A inv: self.generalization->size() = 0
>>    
>>
>
>These two constraints do not say what you want. The first essentially
>says that the superclasses of A cannot have any members. The second says
>that class A cannot itself be a subclass. Neither one prevents, say a
>class B, from being a subclass of A.
>
>In UML 1.4 you could have
>
>  context A inv: self.isLeaf
>  
>
Earl is also not completely right here, I'm afraid. The point is that 
/self/ represents in the context of
class A  (the context is fixed by "context A inv:") an object of class 
A. In the example constraints,
however, /self/ is used as an instance of metatype "Class".

What you try to express here are so-called architectural constraints for 
your
class diagram. OCL does not allow you to formulate architectural constraints
directly in the class diagram but some systems (e.g. Topcased) are 
flexible enough
to process architectural constraints on the metalevel.

For UML1.x you could add, for example, the following well-formedness 
rule to the
metamodel:

context Class inv:
    self.name = 'A' implies self.specialization->isEmpty()

Note that /self.specialization/ denotes all generalization arrows that 
come from subclasses
(if the class with name 'A'  is not allowed to have any subclass, this 
set of
generalization arrows must be empty).


I don't know how to rephrase my constraint for UML2.0 :-(
Do we have UML2.0 experts on this list?

Best regards,
Thomas



-- 
Dr. Thomas Baar
Software Engineering Laboratory
School of Computer and Communication Sciences EPFL
EPFL IC UP-LGL
INJ 337 (Bātiment INJ)
Station 14
CH-1015 Lausanne, Switzerland
Tel +41 21 693 2580, Fax +41 21 693 5079
mailto:thomas.baar@epfl.ch   http://lgl.epfl.ch/members/baar/
Received on Mon 18 Dec 2006 - 17:15:49 GMT