opCmp, opEquals
bearophile
bearophileHUGS at lycos.com
Thu Oct 23 08:04:26 PDT 2008
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:
http://codepad.org/tOHnTObl
I think the C1 design is a bad design and the C2 is the right one, but I'd like to know your opinion.
I think Python 2.6+ uses the C1 design, Python3+ uses the C2 design.
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.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list