Так, прошу прощения. Страуструп придерживается несколько другой точки зрения:
For example, in Section 23.4.3.1 of his book The C++ Programming Language, 3rd edition (Addison-Wesley, 1997), page 703, Bjarne Stroustrup has this to say:
"For example, in mathematics a circle is a kind of an ellipse, but in most programs a circle should not be derived from an ellipse or an ellipse derived from a circle. The often-heard arguments “because that’s the way it is in mathematics” and “because the representation of a circle is a subset of that of an ellipse” are not conclusive and most often wrong. This is because for most programs, the key property of a circle is that it has a center and a fixed distance to its perimeter. All behavior of a circle (all operations) must maintain this property (invariant). On the other hand, an ellipse is characterized by two focal points that in many programs can be changed independently of each other. If those focal points coincide, the ellipse looks like a circle, but it is not a circle because its operations do not preserve the circle invariant. In most systems, this difference will be reflected by having a circle and an ellipse provide sets of operations that are not subsets of each other."
Он не одинок, есть полно статей, где проводится та же идея, что "окружность — не эллипс, квадрат — не прямоугольник". Например:
- K. Baclawski, B. Indurkhya, “The Notion of Inheritance in Object-Oriented Programming” (CACM 37, No. 9, September 1994)
- J. Rumbaugh, “A Matter of Intent: How to Define Subclasses” (Journal of Object-Oriented Programming, September 1996)
- R.C. Martin, “The Liskov Substitution Principle” (C++ Report, March 1996)
Прямо сейчас я не могу найти предложение наследовать эллипс от окружности, но я его точно видел и читал. Может быть, завтра утром смогу отыскать.