On Thu, Apr 7, 2011 at 6:06 PM, Brian Candler <b.candler / pobox.com> wrote:
> Phillip Gawlowski wrote in post #991471:
>>> If you see inheritance as "is a" relationship then inheritance would
>>> be Rational < Real < Complex but not the other way round. Otherwise
>>> you cannot use a subclass instance everywhere you were using a
>>> superclass instance.
>>
>> Though, does the "is a" relationship hold up? I think it's more of a
>> "kind of" relationship, where subsequent classes are defined in ever
>> more detail (so, you'd inherit Floats from Integers, and Complex from
>> Float).
>
> Isn't this the old "ellipse is_a circle, or vice versa" debate?
>
> If you make Circle the top class, then Ellipse reimplements pretty much
> everything (draw, area, etc); there's no useful code sharing. If you
> make Ellipse the top class, then Circle is just a special constrained
> case of Ellipse.
>
> Translating to the current discussion, substitute Float for Circle and
> Ellipse for Complex.
>
> Ruby's answer is: neither is a subclass of the other. Both inherit from
> Numeric. That is, Circle and Ellipse are both a Shape. Or in other
> words, "who cares"?

ACK, ACK and ACK.

> Eventually you come to realise that a lot of what is taught in object
> oriented classes and textbooks is tosh :-)

I'd rather say they are incomplete.  You need those simple examples to
explain what inheritance is for but often books stop right there.
Looking at inheritance on a very abstract level is worthwhile to start
musing about inheritance and how it can best be utilized.  But you
then need to progress discussing technical aspects etc. like we do
here.  But that is more difficult and complex and maybe some authors
are lazy, not aware of the complexity or do not delve into this for
other reasons.  I found Betrand Meyer's "Object Oriented Software
Construction" very comprehensive as he covers a lot aspects of
inheritance.  I would readily recommend it to anyone who wants to dive
a bit deeper into the matter.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/