Possible Duplicate:
Is deriving square from rectangle a violation of Liskov's Substitution Principle?
By applying the LSP, can anyone give me an implementation of Square and Rectangle?
I have read the book - "Head First Object-Oriented Analysis and Design", they said if Sqaure inherit from Rectangle, it violated the LSP but does not have a proper implementation.
Anyone want a try?
If you make Square and Rectangle immutable, then you won't violate LSP.
The issue is if you can independently change the width and height of a Rectangle, and a Square is a Rectangle, then you can change a Square to not be a square.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With