From: "Jim Weirich" <jweirich / one.net> > >>>>> "Gavin" == Gavin Sinclair <gsinclair / soyabean.com.au> writes: > > Gavin> Ruby's mixins have similar features to Java interfaces, but > Gavin> they are more flexible, and don't play any specification > Gavin> role. Also, Ruby classes don't need any interface > Gavin> description to be able to plug-n-play; they just need to > Gavin> support the rigth methods at the right time. > > Interesting ... I've always considered Ruby mixins to be the exact > *opposite* of Java interfaces. Interfaces provide interface without > implementation. Mixins provide implemenation, but aren't required for > interface. > > Just my point of view. > > -- Jim Weirich jweirich / one.net http://w3.one.net/~jweirich And a very fair point of view it is too. But there are some similarities to Java interfaces: class X include Enumerable end x = X.new x.is_a? Enumerable # => true i.e. mixins are a kind of inheritance. But the similarity ends somewhere: no mixin is required for comparing objects, for instance. class Y implements Comparable { public int compare(Object other) { return 0; } } class Y def <=>(other) 1 end end The Java and ruby classes aer now both ready to be sorted, for instance. However, the Java one advertises its comparability, whereas the Ruby one just is comparable. Conclusion: no simple statement can be made about the relationship between Java interfaces and Ruby mixins. Gavin