[xsd-users] how do I...?

Boris Kolpackov boris at codesynthesis.com
Sat May 19 17:52:31 EDT 2007


Hi Ray,

Ray Lischner <rlischner at proteus-technologies.com> writes:

> > (3) Define operator== for comparing books.
>
> I often wonder whether Code Synthesis should generate this operator
> for us. Optional items would be equal if both were absent, or both
> were present and equal. Cardinality > 1 items would be equal using
> the equivalent logic of the std::equals algorithm. Items deriving
> from fundamental types would be equal if the values were equal.

This all is already working like you described.


> Complex types would be equal if all their members were equal.

I think in many cases equality defined this way won't be what
the application needs. In case of a book, for example, I would
define equality as ISBNs being equal or IDs being equal or
titles being equal, depending on the application What if two
editions of the same book have different ISBNs? Finally, I doubt
anybody would find comparing availability attribute meaningful.


> I've often found myself wishing for an auto-generated operator==
> when writing unit tests. At other times, I've managed to get by
> writing operator== manually, but always, my definition has been
> memberwise comparison for equality.

Yes, unit tests are probably the only case where memberwise comparison
is what one needs most of the time. I think we can have an option that
triggers generation of operator== and operator!= for complex types.


Thanks for the suggestion!

-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20070519/c9795331/attachment.pgp


More information about the xsd-users mailing list