[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 2:57:40
[Download RAW message or body]

On Thursday, October 17, 2002, at 12:26 PM, Paul Brannan wrote:

> On Fri, Oct 18, 2002 at 03:02:53AM +0900, Chris Gehlker wrote:
>>> What would keep you from turning your cluster base class into a 
>>> Module,
>>> and using it as a mixin?
>>
>> Because the 'is a' relationship is going the opposite direction. I use
>> Modules in Ruby where I would use MI in C++ and cluster bases where I
>> would use virtual classes. That way I have a nice clean inheritance
>> tree.
>
> module Foo1
> end
>
> class Bar1
>   include Foo1
> end
>
> b = Bar1.new
> p b.is_a?(Foo1) #=> true
>
> class Foo2
> end
>
> class Bar2 < Foo2
> end
>
> b = Bar2.new
> p b.is_a?(Foo2) #=> true
>
> The "is a" relationship looks to me like it's going the same direction
> in both cases.
>

All I can say is "look again." In the first example, the class is 
inheriting from the module, not the other way around. Let me try to 
draw it. My arrows go from the parent to the child, that is, 
anti-Stroustrup.

Example 1

__________         ________
| Object |         |  Foo1 |
  --------          |_______|
       |                 |
       \                 /
        \               /
         \             /
          \           /
           \         /
            \       /
             \     /
              \   /
               \ /
                |
                V
             -------
             | Bar1 |
             -------

Example 2

    -----------
    | Object  |
    -----------
         |
         V
    -----------
    | Foo2    |
    -----------
         |
         V
    -----------
    | Bar2    |
    -----------


Virtual Class / Class Cluster Example
                               ------------
                               | Object   |
                               ------------
                                     |
                                     V
                             ------------------
                             | Cluster/Virtual |
                             |  Base Class     |
                             -------------------
                                     |
                                    /|\
                                   / | \
                                  /  |  \
                                 /   |   \
                                /    |    \
                               /     |     \
                              /      |      \
                             /       |       \
                            /        |        \
                           /         |         \
                          /          |          \
                         /           |           \
                        |            |            |
                        V            V            V
                   ---------   ----------      ---------
                   | Child1 |  | Child2  |     | Child3 |
                   ----------  -----------     ----------


Hope that helps
-- 
Cogito Ergo Spud. - I think therefore I yam.


<fontfamily><param>Courier</param>

On Thursday, October 17, 2002, at 12:26 PM, Paul Brannan wrote:


<excerpt>On Fri, Oct 18, 2002 at 03:02:53AM +0900, Chris Gehlker wrote:

<excerpt><excerpt>What would keep you from turning your cluster base
class into a Module,

and using it as a mixin?

</excerpt>

Because the 'is a' relationship is going the opposite direction. I use 

Modules in Ruby where I would use MI in C++ and cluster bases where I 

would use virtual classes. That way I have a nice clean inheritance 

tree.

</excerpt>

module Foo1

end


class Bar1

  include Foo1

end


b = Bar1.new

p b.is_a?(Foo1) #=> true


class Foo2

end


class Bar2 << Foo2

end


b = Bar2.new

p b.is_a?(Foo2) #=> true


The "is a" relationship looks to me like it's going the same direction

in both cases.


</excerpt>

All I can say is "look again." In the first example, the class is
inheriting from the module, not the other way around. Let me try to
draw it. My arrows go from the parent to the child, that is,
anti-Stroustrup.


Example 1


__________         ________

| Object |         |  Foo1 |

 --------          |_______|

      |                 |

      \                 /

       \               /

        \             /

         \           /

          \         /

           \       /

            \     /

             \   /

              \ /

               |

               V

            -------

            | Bar1 |

            -------


Example 2


   -----------

   | Object  |

   -----------

        |

        V

   -----------

   | Foo2    |

   -----------

        |

        V

   -----------

   | Bar2    |

   -----------



Virtual Class / Class Cluster Example

                              ------------

                              | Object   |

                              ------------

                                    |

                                    V

                            ------------------

                            | Cluster/Virtual |

                            |  Base Class     |

                            -------------------

                                    |

                                   /|\

                                  / | \

                                 /  |  \

                                /   |   \

                               /    |    \

                              /     |     \

                             /      |      \

                            /       |       \

                           /        |        \

                          /         |         \

                         /          |          \

                        /           |           \

                       |            |            |

                       V            V            V

                  ---------   ----------      ---------

                  | Child1 |  | Child2  |     | Child3 |

                  ----------  -----------     ----------

                


Hope that helps

-- 

Cogito Ergo Spud. - I think therefore I yam.

</fontfamily>

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

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