> -----Original Message----- > From: nosuzuki / e-mail.ne.jp [mailto:nosuzuki / e-mail.ne.jp]On Behalf Of > Adam Spitz > Sent: Thursday, December 14, 2000 12:40 PM > To: ruby-talk ML > Subject: [ruby-talk:7252] Multiple inheritance and mixins > > > I'm having trouble understanding the difference between Ruby's mixins > and "ordinary" multiple inheritance. Can someone explain to me how > mixins are different from, say, C++'s version of multiple inheritance? > Which of C++'s problems has Ruby avoided? Is there anything you can do > with multiple inheritance that you can't do with mixins? > Basically Ruby's include corresponds to C++'s virtual inheritance. For example, you can have an inheritance graph of Ruby Classes BC, XBC,XYBC and Ruby Modules X,Y,XYB. X B C // \\ // \\ / Y XB BC \\ // \\ / XYB XBC \\ / XYBC "--" is Ruby inheritance and "==" is Ruby include. In C++ land this translates to "--" is public inheritance and "==" is virtual public inheritance. Note that you are not allowed to create instances of Ruby Modules (sort of like C++ abstract classes ). Ruby has a pretty straightforward way to resolve the ambiguity problem resulting form it's restricted form of MI ... the code snippet module A def f() p 'A' end end module B def f() p 'B' end end class C def f() p 'C' end end class D < C end x = D.new x.f class D include A end x.f class D include B end x.f has the output - C A B. Don't forget that Ruby's object model is in some respect more complicated then C++'s object model - there is no C++ equivalent for Metaclasses. Christoph