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

List:       ruby-talk
Subject:    Re: Interfaces in Ruby
From:       Paul Brannan <pbrannan () atdesk ! com>
Date:       2002-10-18 13:36:45
[Download RAW message or body]

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.  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


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

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