[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Interfaces in Ruby
From:       Chris Gehlker <canyonrat () mac ! com>
Date:       2002-10-18 14:21:17
[Download RAW message or body]


On Friday, October 18, 2002, at 06:36 AM, Paul Brannan wrote:

> On Fri, Oct 18, 2002 at 11:57:40AM +0900, Chris Gehlker wrote:
>> Example 1
>>
>> __________         ________
>> | Object |         |  Foo1 |
>>  --------          |_______|
>>       |                 |
>>       \                 /
>>        \               /
>>         \             /
>>          \           /
>>           \         /
>>            \       /
>>             \     /
>>              \   /
>>               \ /
>>                |
>>                V
>>             -------
>>             | Bar1 |
>>             -------
>
> I think your diagram here is slightly off.  Ruby has only single
> inheritance; there is no multiple inheritance, even if mixins give the
> illusion of (and often advantages of) MI.

I consider mixins to be a *form* of MI. I would go so far as to say 
that it is the only form that I've actually seen usefully employed even 
in C++ code. Your example below and your previous example with is_a 
show that it passes the duck test. But even if you want to consider the 
it to be "the illusion of multiple inheritance" it's important to 
maintain the illusion. Which is why I think it important to use class 
clusters as well as mix-ins.

> In this example, Bar1
> inherits from a proxy class Foo1' which inherits from Object.  To
> illustrate this better:
>
> class Base
>   def foo
>     puts "Base"
>   end
> end
>
> module M1
>   def foo
>     puts "M1"
>     super
>   end
> end
>
> module M2
>   def foo
>     puts "M2"
>     super
>   end
> end
>
> class Derived < Base
>   include M1
>   include M2
>   def foo
>     puts "Derived"
>     super
>   end
> end
>
> d = Derived.new
> d.foo #=> Derived
>           M2
>           M1
>           Base
>
> See also [ruby-talk:03591].
>
> Paul
>
>
>

--
There are two kinds of fool. One says, "This is old, and therefore 
good."
And one says, "This is new, and therefore better."
-John Brunner, science fiction writer (1934-1995)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic