From: Chris Gehlker Date: 2002-10-18T11:57:40+09:00 Subject: Re: Interfaces in Ruby --Apple-Mail-6-768082070 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed 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. --Apple-Mail-6-768082070 Content-Transfer-Encoding: 7bit Content-Type: text/enriched; charset=US-ASCII Courier 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. --Apple-Mail-6-768082070--