Rex Kerr
1 min readJan 20, 2025

--

The key problem comes when we want to give our Rectangle functionality.

In terms of data alone, a Square _is_ a Rectangle. But it is NOT a Rectangle That Can Stretch Itself.

It's this fundamental tension between LSP and encapsulation (where we want Rectangle not just to be InertRectangleData but RectangleThatCanDoRectangleStuff) that makes OOP a less-widely-usable paradigm than was once hoped.

(ImmutableRectangleThatCanProduceAStretchedCopy is also not the solution, because it is just data, but now the natural subtyping is that ImmutableSquareThatCanProduceAScaledCopy is a supertype of the rectangle, since the rectangle can both make scaled copies and stretch itself. So the problem isn't solved.)

OOP is still very useful in the right situations. But it's very important to clearly discern what those situations are, and taking LSP very seriously indeed is one of the most important steps towards correctly discerning those situations--thanks for helping set people on the right track in this regard!

--

--

Rex Kerr
Rex Kerr

Written by Rex Kerr

One who rejoices when everything is made as simple as possible, but no simpler. Sayer of things that may be wrong, but not so bad that they're not even wrong.

No responses yet