Hacker News new | ask | show | jobs
by dragonwriter 4711 days ago
> If Square and Rectangle had only getter methods (i.e., they were immutable objects), then no violation of LSP could occur.

Yeah, this is the fundamental problem; mutable objects tend to result in LSP violations when class heirarchies follow common sense is-a relationships, but mutating operations are not limited to those (if any exist) that preserve identity.

A corollary to this is that the use of default constructors very often accompanies LSP violations, as it usually implies all of the object's state is subject to mutating operations.