Re: OCL equal (=) operator , comparing identities



Date view Thread view Subject view Author view Attachment view

From: Anneke Kleppe (a.kleppe@klasse.nl)
Date: Fri 25 Jun 2004 - 09:14:58 BST


Hi,

Soma answers:
    * The = operator is NOT a shorthand for the OclAny::=(OclAny) 
predefined operation, it IS the OclAny::=(OclAny) predefined operation. 
However, like in every OO system, subclasses may redefine this operation. 
Thus, the subclass Boolean redefines it by restricting the parameter to be 
of type Boolean (in a precondition). The other primitive types redefine it 
in a similar fashion. The collection types redefine the operation as 
explained in section 9.2.1 of our book, taking into account the equivalence 
of the elements in both collections. Each user defined class may override 
the '=' operation in its own way. If this is not done, object identity is 
used to determine the outcome.
    * Yes, c1=b1 is equivalent to c1.=(b1). Because '=' is defined as an 
infix operation you may use the first notation.
    * Is there somewhere a precise specification explaining how operations 
are called (including operations defined in diverse paths of a - multiple - 
inheritance)? Not for user defined types. This should be part of the UML 
specifaction. The OCL standard library does not include any multiple 
inheritance, therefore you can determine which standard lib operation is 
called by using the 'normal' inheritance rules.
    * Just a non-connected additional question: does TupleType inherit from 
OclAny? Yes, it does. For this type, equivalence (the '=' operation) is 
defined such that its result is true iff all parts of the tuple instances 
are equal.
Cheers,
Anneke Kleppe


At 02:45 PM 24-06-2004, you wrote:

>Hello<?xml:namespace prefix = o ns = 
>"urn:schemas-microsoft-com:office:office" />
>
>
>
>Here is something I believe since a long time, and I would like somebody 
>to confirm it...
>
>The = operator is nothing but a shorthand for the OclAny::=(OclAny) 
>predefined operation. This means we can compare any kind of object but 
>collections... So
>
>c1=b1
>
>is strictly equivalent to
>
>c1.=(b1)
>
>which is totally legal since both c1 and b2 conform to OclAny ! (unlike 
>the specification states, OCL2.0 final 7.4.5 p.12: "You cannot, for 
>example, compare an Integer with a Boolean or a String.").
>
>This operation is defined as: "True if self is the same object as 
>object2." So it compares objects and not their slots... Obviously, if two 
>objects have not the same type, these are not the same objects and then 
>the result is false...
>
>
>
>A question arises then:
>
>which operation is called when I define one of the
>
>C::=(OclAny) => should override OclAny::=(OclAny)
>
>C::=(B) => should be called rather than OclAny::=(OclAny)
>
>C::=(C) => should not be called assuming B does not conform to C...
>
>
>
>Is there somewhere a precise specification explaining how operations are 
>called (including operations defined in diverse paths of a - multiple - 
>inheritance)?
>
>
>
>Just a non-connected additional question: does TupleType inherit from OclAny?
>
>
>
>Frédéric Fondement

Klasse Objecten
Chalonhof 153
NL - 3762 CT Soest
The Netherlands
voice: +31(0)35-6037646
fax: +31(0)35-6037647
http://www.klasse.nl 

Date view Thread view Subject view Author view Attachment view