Skip to main content
added 163 characters in body; added 1 character in body
Source Link

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 might make better sensewithout 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, then we would't break LSP. 

Another way to think about it: does a mutable Square really behave like a mutable 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 it might make better sense 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, then we would't break LSP. Another way to think about it: does a mutable Square really behave like a mutable Rectangle?

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?

deleted 281 characters in body
Source Link

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 it might make better sense 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, then we would't break LSP. If we want to work with rectangles for muting state, then we could also implement an implicit cast operator in class Square, that casts Square to Rectangle and then after that we get a Rectangle that behaves like a Rectangle, but of course its not reference of same object anymore. Another way to think about it: does a mutable Square really behave like a mutable 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 it might make better sense 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, then we would't break LSP. If we want to work with rectangles for muting state, then we could also implement an implicit cast operator in class Square, that casts Square to Rectangle and then after that we get a Rectangle that behaves like a Rectangle, but of course its not reference of same object anymore. Another way to think about it: does a mutable Square really behave like a mutable 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 it might make better sense 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, then we would't break LSP. Another way to think about it: does a mutable Square really behave like a mutable Rectangle?

Source Link

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 it might make better sense 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, then we would't break LSP. If we want to work with rectangles for muting state, then we could also implement an implicit cast operator in class Square, that casts Square to Rectangle and then after that we get a Rectangle that behaves like a Rectangle, but of course its not reference of same object anymore. Another way to think about it: does a mutable Square really behave like a mutable Rectangle?