On Wed, 18 Apr 2001, Stephen White wrote:
> > In Ruby, the best you can do is always begin by creating a module you can
> > mixin into later classes. Too bad this is not a common practice yet. Do
> > you know what I do? If I have modules that usually, but doesn't have to
> > "inherit" (include) from eachother, I instead include them all in my class
> 
> Any comments on this style of programming? It sounds like an interesting
> new approach I haven't seen before.

I use a technique I called side-inheritance which I will describe as
follows: calling super from a mixin that has no super-mixin.

You have a mixin you construct only by including mixins A,B in that order.
That's the methods of B on top of the methods of A, such that if super
"falls through" in B, it gets to go through A, although nothing in the
definition of B talks about A.

Here is an example of what you can do, formally described: A provides an
interface that B requires. B provides that interface. This needs not be a
full implementation: if B is empty and requires A, then B provides A. What
is required is that whatever you implement of that interface should still
respect the contract (you will usually call super, save the result, return
the result, and do things before and/or after the result)

This is how I implement run-time checking of contracts. This is "Design by
Contract" without a source filter, without method renaming, and without
AOP (aspect oriented programming). See MetaRuby-0.6.

This is also how MetaRuby-cvs-current has its undo/redo function
implemented uniformly across all of Array/Hash/String. In this case, the
undo/redo module also provides an additional interface, consisting of
#undo() and #redo().

Basically you get to think more about the layering of interfaces in your
layering of superclasses and end up decoupling those in separate modules.

(Ruby's distinction of classes and modules almost becomes a hurdle at some
point. classes are modules, but include works only on non-class modules;
a class is like the zeroth module a class includes, but can't be included 
by a non-class module; etc)

matju