FAQ 7.07 What is specialization?

A major source of confusion and design errors.

Some people assume that proper inheritance can be determined by the vague concept of specialization. For example, if Derived is a special Base, some people assume that Derived can be derived properly from Base. While this simple rule works some of the time, it is incorrect often enough to be misleading. The guiding principle is for the derived class to behave like the base class, and specialization sometimes leads designers in the wrong direction.

One problem with the concept of specialization is that it can be ambiguous. Does it mean "better than" (JetPlane is a specialized Plane) or "more skilled" (Doctor is a specialized Person) or "subset of" (Circle is a specialized Ellipse) or "more specific" (Unix is a specialized Operating System) or "restricted" (a List that can only contain Circle objects is a specialized List that can contain any Shape)? Because of the potential ambiguity, it is hard to make a blanket statement about specialization as a reliable approach to public inheritance.

Not only is it ambiguous, but in certain cases it is completely incorrect. In particular, specialization does not imply that Derived must support all the operations defined by Base, as is necessary for proper inheritance.

Forget specialization and learn about substitutability.



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