3 ms·
> OOP is a tool like any other and isn't always suitable. A similar example from geometry: all squares are rectangles, but you wouldn't implement a square type
by dragonwriter 2y ago
> OOP is a tool like any other and isn't always suitable. A similar example from geometry: all squares are rectangles, but you wouldn't implement a square type by deriving from rectangle because it breaks LSP.
Deriving a class where each instance models a geometric square from one that models a rectangle would not violate LSP.
Deriving a class where each instance models an entity which is at any point in time a geometric square but can become a different square while retaining its identity from one that models an entity with the same relationship to geometric rectangles, in a language where mutable objects must be of a fixed class, will violate the LSP.
People often discuss OOP but fail to differentiate those two very different cases. (And more generally, pay too little attention to the impact of mutability on is-a relationhlships.)