Skip to main content
3 of 3
added 163 characters in body; added 1 character in body

AFoursidedShape hides information about the dependencies between height and width, so LSP is not violated as is the case with Square inhereting from Rectangle.

The class rectangle and square are representations of squares and rectangles, therefor they do not necessary share the same relationship as what they represent. In other words a mathemtical Square has a relationship with mathemtical rectangle, but that does not imply the class square must necesseraly have same relationship with class rectangle. If we still want to treat Square as a Rectangle another way of doing it without violating LSP could be to have an interface thats called ARectangleReader which only has contract for the getters getHeight and getWidth which is implemented by the Square class and Rectangle class.

Another way to think about it: does a mutable Square really behave like a mutable Rectangle?