opCmp, opEquals

Stewart Gordon smjg_1998 at yahoo.com
Tue Oct 28 10:32:19 PDT 2008


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:gdq3pq$126t$1 at digitalmars.com...
>I have a small question regarding OOP design. The signature of opCmp, 
>opEquals when defined inside classes require a Object argument.
> So you have to define what to do when the given object can't be cast to 
> the this class. Here you can see two alternative designs:
<snip>
> Someone told me that Java uses a mixed approach: the opEquals returns 
> false when the cast is not possible, while the cmp throws an exception.

This seems sensible to me.  If two objects are of completely different 
classes, obviously they aren't equal to each other.  But there's no means by 
which one can be picked out as being 'less than' the other.

Stewart.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies 
on the 'group where everybody may benefit. 



More information about the Digitalmars-d-learn mailing list