Automatic conversion

Automatic conversion

From: Thomas Baar ^lt;>
Date: Fri 10 Mar 2006 - 13:34:21 GMT
Message-ID: <>
D H. Akehurst wrote:

>You can use the invariant
>context Department inv: 
>   self.person->forAll(salary < self.maxSalaryDept)
>In the case where the multiplicity is [0..1].
>Using the '->' operator on objects that are not collections automatically wraps
>the object in a Set.
>Wraping an undefined value into a set results in an empty set, hence your expression
>gives true when there are no managers.

I'm very puzzled by the automatic conversion to collections, it would mean
that, for example,  5->forAll(x| ...) would be syntactically correct!
What would then be the point to have two different operators '.' (dot) and
'->' (arrow) in OCL? So far, it helped the reader to find out if the source
expression is of object or collection type.

Another question about the emptySet <-> undefined conversion: Wouldn't it be
wise to have the following two constraints equivalent (in case of 
multiplicity [0..1]?


context Department inv: 
   self.person->forAll(...   -- here the object self.person is automatically converted into a collection

context Department inv: 
   Set{self.person}->forAll(...   -- here the object self.person is manually converted into a collection
                                  -- by wrapping it with Set{  }

Both versions are however not equivalent once that automatic emptySet<-> 
conversion is adopted. If self is not linked with any other person then 
in case
of automatic conversion we had

context Department inv: _emptyset_ -> forAll(...) 
what evaluates always to true.

In case of manual conversion we had

context Department inv: Set{_oclVoid_}->forAll(..)
what is not always true.

To summary: The automatic conversion of x into a collection type cannot 
be simulated by
Set{x}. However, this would be (at least for me) the most natural 
semantics for the automatic conversion...

Best regards,

Dr. Thomas Baar
Software Engineering Laboratory
School of Computer and Communication Sciences EPFL
INJ 337 (Bātiment INJ)
Station 14
CH-1015 Lausanne, Switzerland
Tel +41 21 693 2580, Fax +41 21 693 5079
Do not miss MoDELS/UML 2006: see for the 9th International Conference on Model Driven Engineering Languages and Systems (formerly the UML series of conferences)
Received on Fri Mar 10 13:34:54 2006