Forgive another shape example, but this one is routinely cited as a good exemplar of poor inheritance involving squares inheriting from rectangles.
This example gets debated, a lot. I've read folks respond in forums in all sorts of ways but my favourite challenge was "I have yet to see
a square that wasn't a rectangle. Can you draw me one?". An excellent question, but one that manages to entirely miss the crux of the problem.
If you think about it, a square is a special type of rectangle (just one where the width and height are the same). But the problems begin when you
consider the two shapes, specifically from a programmers perspective. A rectangle needs two descriptive arguments while a square only needs one. You
can freely change the width of a rectangle and it still remains a rectangle, but if you were to change the width of a square (without altering
the height) then it would stop being a square. So the SetWidth-Method in our Square class can't be correct, because if it alters only the width you'll
have a Square that isn't square. If it changes both the width and the height, then it isn't doing what the base version of the method does, which means
the Liskov substitution principle is violated. Leaving aside these more abstract issues, it is also visually ugly, given the readability of a SetWidth
method in a square class is logically inconsistent with the shape. I'd read this as a programmer and immediately feel uneasy. What other logical flaws
am I about to walk into?