DEV Community

[Comment from a deleted post]
Collapse
 
franzliedke profile image
Franz Liedke

You claim that your example of the Liskov Substitution Principle breaks that principle.

The way I understand that principle, it actually isn't.

LSP is about being able to use a subtype in place of its parent. It doesn't say that the behavior needs to be exactly the same. In fact, there would not be much point in introducing subclasses if they had to behave exactly like their parents.

To quote LSP again:

an object of type T may be substituted with any object of a subtype S without altering any of the desirable properties of T

So, the point here is this: what are the desirable properties? Do they include a certain algorithm for the implementation of the getArea() method, or rather that the method returns an integer that describes the area of whatever object it is a part of, using whatever algorithm is fitting for that object?