From: Robert Klemme Date: 2012-02-05T02:03:23+09:00 Subject: Re: Inheritance in other notation On Sat, Feb 4, 2012 at 3:56 PM, Josh Cheek wrote: > On Sat, Feb 4, 2012 at 7:03 AM, Robert Klemme wrote: > >> On Sat, Feb 4, 2012 at 2:14 AM, Jeremy Bopp wrote: >> >> > The constant Square is a class effectively equivalent to conventionally >> created classes, so you don't have to do anything special to make Rectangle >> descend from it. Just do it as you originally expected: >> > >> > class Rectangle < Square >> >  ... >> > end >> >> Which leaves us with the "minor" issue that a rectangle _is not_ a >> square - it's the other way round.  Yeah, I know, implementation >> inheritance vs. conceptual inheritance.  But OP should be aware of >> this. > Probably neither should inherit from the other since they break Liskov > Substitution Principle. Good point! But classes Rectangle and Square need not necessarily implement the mathematical idea of them - or not completely. > rect.x = 2 > rect.y = 4 > > Now what is the value of rect.x? When rectangle, this will be 2. When > square, will it be 4? Squares don't have setters/getters for individual > sides since their sides must change together. Well, or setters change all in the same way. It all depends for what you need those classes and how you model it. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/