FAQ 7.04 Isn t the difference between proper and improper inheritance obvious?

FAQ 7.04 Isn't the difference between proper and improper inheritance obvious?

Apparently not.

Improper inheritance is a very common design error. This seems to be because developers base inheritance relationships on their intuition rather than the objective criteria of substitutability.

The following inheritance relationships are improper because the derived class either requires more or promises less.

  • A Stack is not a kind-of List (assuming List provides member functions that allow insertions in the middle of the list and Stack does not).

  • A ListOfApples is not a kind-of ListOfFruit (assuming that any type of Fruit can be put into a ListOfFruit).

The following inheritance relationships may or may not be proper inheritance depending on the specified behavior of the base class and the derived class.

  • A Circle may not be a kind-of Ellipse.

  • An Ostrich may not be a kind-of Bird.

  • An Integer may not be a kind-of RationalNumber.

These examples are explained in Chapter 8.



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