5 ms·
The real takeaway from the circle-ellipse problem is that mutators and conversion methods are inappropriate for use in inheritance. Essentially these operations
by codehero 15y ago
The real takeaway from the circle-ellipse problem is that mutators and conversion methods are inappropriate for use in inheritance. Essentially these operations (including stretching) are merely a more complicated form of class casting.
Perhaps the worst offender of this principle is the toString() method. A class designer must not suppose that the string representation he implements should be the canonical representation of that class. Instead, he should provide the user with accessors and iterators, and provide an external string conversion function which generates the strings from these methods.
- raganwald 15y agoI agree that a class designer need not suppose that "the string representation he implements should be the canonical representation of that class," however if you take that line, you should not suppose that any class ought to know how to convert itself to another class. If phone numbers shouldn't know their canonical representation as strings, then why should circles know their canonical representation as ellipses? Perhaps, as you suggest, this is a function that should be external to the instances. But I repeat myself: http://weblog.raganwald.com/2007/10/too-much-of-good-thing-not-all.html http://weblog.raganwald.com/2007/10/too-much-of-good-thing-n...