From: Robert Klemme Date: 2010-09-24T16:17:49+09:00 Subject: Re: composition vs 'leaf-class mixins' (vs class inheritance) On Fri, Sep 24, 2010 at 3:42 AM, Woody Peterson wrote: > It's not just that schools focus on inheritance as the key part of OO, > it's also that OO language designers tend to build in inheritance as a > very dominant concept (in opposition to ex. Alan Kay's statements that > message passing should be the dominant concept of OO). Solving problems > in terms of the languages' built-in dispatching sure seems like it > shouldn't be of such limited use. That said, I find a lot of value in > separating concerns and clean tests, so for now my real-world problems > will most likely avoid using this 'leaf-class mixin' technique as an end > goal. I believe inheritance is overrated and often overused. In teaching inheritance is often introduced as "is a" relationship which is correct IMHO. There are two sources of overuse: people design "is a" relationships between types which do not model reality in a way which yields good software (i.e. reusable, modular etc.; as in this example with skills). The other source of overuse is using inheritance as "implementation inheritance". This is a problem in languages which do not allow private inheritance, i.e. in which you cannot prevent type compatibility. In C++ you can inherit privately and in Eiffel there are even more sophisticated mechanisms to control visibility of inherited features. In those languages inheritance which does not model "is a" is possible and OK. But in Java for example you neither have MI nor control over visibility. Here, inheritance (and implementing interfaces) always means "is a". In Ruby the situation is similar to Java: mixin and inheritance are always visible (you can do x.kind_of? ModuleY an get true if x's class mixes in ModuleY) so it always means "is a". Although you can apply some tricks and use metaprogramming to change that in a way, that will give you quirky code. Btw, thank you for bringing up an interesting topic for discussion! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/