Re: OO Concept: Liskov Substitution Principle



Joshua Cranmer wrote:
The problem with compatibility is that SquareMatrix assumes that its two dimensions are equal; since these dimensions can only be affected at initialization, thereby rendering this contractual incompatibility moot.

That is not a contractual matter but an implementation matter.

However, in the end, we decide that requiring a separate SquareMatrix class is pointless since a 3x2 matrix multiplied by a 2x3 matrix is a square matrix even if its type is merely a banal Matrix, rendering the entire discussion moot.

The requirement that a SquareMatrix have the same width and height is not a contract issue, since none of the methods or constructors have to make that an externally visible invariant. One could treat a SquareMatrix as a normal Matrix and let it handle its own Squareness in an encapsulated way.

--
Lew
.