FAQ 8.10 What is the one issue in these FAQs that doesn t seem to die?

FAQ 8.10 What is the one issue in these FAQs that doesn't seem to die?

graphics/new_icon.gif

Trying to solve the "circle deriving from ellipse" relationship by having ellipse derive from circle.

We like getting e-mail. We like getting letters. We like receiving phone calls. We appreciate kind words and advice. But, please, no more talk about circles, ellipses, and how the two can be related. Many people have suggested that a "solution" to trying to derive a circle from an ellipse is to derive the ellipse from the circle. That is not a dependable solution, despite the mathematical arguments, and it misses the fundamental OO issue of substitutability that is controlled by expectations. Look at it this way: at a topology conference, everyone "knows" that a coffee cup is the same as a doughnut because their fundamental groups are the same. But when topologists have breakfast, they recognize that these two concepts are not substitutable. Most of the time they manage to eat the donut and pour coffee into the cup. So it's a question not of reality but of perception and context.

It really doesn't matter what mathematics says about circles and ellipses. The entire discussion comes down to adherence to the specification of the base class. Reality, mathematical or otherwise, is irrelevant.

Ellipse can be substitutable for Circle if you say so up front and avoid logical impossibilities. Circle can be substitutable for Ellipse if you say so up front and avoid logical impossibilities. Ostrich can be substitutable for CoffeeCup if you push it hard enough, but either Ostrich or CoffeeCup is going to have a weird interface. The point is that substitutable interfaces can be forced or they can be natural, but either way, proper inheritance requires substitutable interfaces.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net