Re: Automatic conversion
Thomas Baar wrote:
> D H. Akehurst wrote:
>> You can use the invariant
>> context Department inv: self.person->forAll(salary <
>> 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
> that, for example, 5->forAll(x| ...) would be syntactically correct!
> What would then be the point to have two different operators '.' (dot)
> '->' (arrow) in OCL? So far, it helped the reader to find out if the
> expression is of object or collection type.
I don't quite see your problem here. The different operators have been
introduced specifically to allow for automatic conversion. Without such
a conversion there would be no need for the operators as the parser
would always be able to decide whether the source is a collection or not
and, thus, whether a.forAll is valid OCL. By using '->' you essentially
state that you intend the source to be used as a collection, whatever it
really is. Conversely, by using '.' you state that you want to use the
source as a scalar, whatever it really is. This happens, for example, in
navigation expressions, where ->collect(...) expressions are
automatically inserted---even though in the last revision of the
standard I couldn't find anything about this anymore.
Dipl.-Inf. Steffen Zschaler
Technische Universitšt Dresden
Department of Computer Science
Phone +49 351 463 38555
Fax +49 351 463 38459
Received on Fri Mar 10 13:50:56 2006