From: Paul Brannan Date: 2002-10-16T23:12:49+09:00 Subject: Re: Interfaces in Ruby On Wed, Oct 16, 2002 at 01:30:04PM +0900, Chris Gehlker wrote: > > On Tuesday, October 15, 2002, at 09:02 PM, Edward Wilson wrote: > > > Is there a way to write/inforce interfaces in Ruby like one can using > > Abstract Classes in C++ or Interfaces in Java? > > > > If not, how has everyone been approaching this? > > > I don't think C++ abstract classes are that similar to Java interfaces. Not having used Java interfaces extensively, I can't speak about their subtleties, but Java interfaces and C++ abstract classes are used for similar functions. Both are used to say "this class implements this set of functions." This is particularly important in C++, since, through the magic of virtual functions, it allows me to write a single function that can accept objects of many different types, without using templates. This is less useful in Ruby, since an object always retains its type when I pass it as a parameter to a method (whereas in C++ I only have a reference to the base class). > I don't see the need for interfaces in a language with mix-ins. This doesn't make sense to me. I see interfaces and mixins as orthogonal concepts; interfaces are used to specify a contract, while mixins are used to provide additional methods to a class. > When I want something like a C++ abstract class, I use a class > cluster. Maybe that's just my ObjC background showing. What is a "class cluster"? Can you provide an example? Paul