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
by vinkelhake 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.
> Adding a new operation on numbers requires modifying all the classes.
This is part of the expression problem. With an OOP approach, adding a new operation is a "heavy" task. With a functional approach, adding a new type is a heavy task.
In the case of the numerical tower, the set of types is more or less locked down.
- 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.)