tag:blogger.com,1999:blog-2062585365039898952.post8141493813746562520..comments2013-09-10T23:15:49.334-07:00Comments on Blogueando: The Liskov Substitution PrincipleJAVIER NAVARROhttps://plus.google.com/105682769842466535458noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-2062585365039898952.post-12615048843768659972011-08-17T07:57:41.662-07:002011-08-17T07:57:41.662-07:00Thanks for your comment. Definitely, we can encaps...Thanks for your comment. Definitely, we can encapsulate a Rectangle instance in the Square class definition, and delegate the calculation to the Rectangle object, thus the IS_A relationship turns into a HAS_A. There is a famous OOD phrase which goes: "COMPOSITION OVER INHERITANCE."<br /><br />We just need to be careful when defining our class abstractions and sub-classing.Javier Navarro-Machucahttps://www.blogger.com/profile/09521205407842495895noreply@blogger.comtag:blogger.com,1999:blog-2062585365039898952.post-9998106860107152182011-07-26T07:20:44.088-07:002011-07-26T07:20:44.088-07:00Your blog postings on S.O.L.I.D. is really "S...Your blog postings on S.O.L.I.D. is really "SOLID" so far. I look forward to the last two entries as well.<br /><br />I explain LSP with Rectangle and Square. We've all be taught from elementary school on that a square is a type of rectangle where the sides are the same length.<br /><br />It's very easy to derive Square from Rectangle. "Is-a" even appears in our earliest definitions.<br /><br />However, unlike simple geometry, we can often change the length of the sides of a Rectangle class, and this is where the Square runs into problems.<br /><br />We can still use the Rectangle to implement the Square. We just treat Rectangle as an attribute to Square and delegate all geometric calculations from Square to the private Rectangle. Here we can control the sides of the rectangle keeping them the same without any LSP concerns.Anonymousnoreply@blogger.com