Campbell Ritchie wrote:Back to the LSP: Have you seen the square‑rectangle example? There seem to be many copies of it available all across the net.
The problem with the square‑rectangle example is that a square “IS‑A” rectangle, but a square object “ISN'T‑A” rectangle object.
Are we saying that a Manager is an Employee but a Manager object isn't an Employee object?
A damn fine question, but I suspect that the answer is "yes" - at least if you accept that a Manager is a significant distinction in the hierarchy, because it's invariants
are the same.
What's possibly closer to the problem is: Is there such a thing as a "vanilla" Employee? (ie, should
Employee be
abstract - posed by Chan earlier, as I recall) - and I suspect that the answer to that may well be "no".
I found Bloch's quote about the impossibility of adding fields and maintaining the equals contract when you add fields to a class yesterday, and I think the lesson is that inheritance is difficult and you need to be careful about it.
Amen. It also suggests to me that the SOLID acronym should possibly be "Frenchified" to SOLID
E.
However, one might assume, from our discussion, that hierarchies are totally spurious; and I certaintly don't think they are. There
are things that fit naturally into a hierarchical structure; just maybe not as many, or as simply, as we thought.
Would you like a language that
didn't have an
extends keyword?
Winston