4 ms·
> In this way, a Rectangle is more like a child of a square: widening its capabilities. Yes, but this will violate the Liskov Substitution Principle, which (ef
by BeetleB 6y ago
> In this way, a Rectangle is more like a child of a square: widening its capabilities.
Yes, but this will violate the Liskov Substitution Principle, which (effectively) states that any program that is correct for a class (Square) should be correct for the subclass (Rectangle).
So a program that takes in a parent class (Square) can rely on the sides being equal. Now pass in a child class (Rectangle) and your program may break. Hence the violation.