Robert Klemme
9/20/2008 9:12:00 AM
On 17.09.2008 10:40, James Coglan wrote:
> [Note: parts of this message were removed to make it a legal post.]
>
>> To avoid the method confusion while having more than one module, Ruby
>> looks in a particular order. This can be applied in the case of super
>> classes as well and let ruby follow the order of import while searching
>> for a method. Thus i may have,
>>
>> class MyClass < A < B #[oder of method search will be from MyClass, A to
>> B]
>>
>> I believe that there might be some strong reason for allowing multiple
>> Modules while restricting only one Parent ...?
>
> This is likely just my opinion, but it's mostly a question of semantics, of
> indicating your intent to other programmers. If you want to make a more
> specialised kind of MyClass object, you'd subclass MyClass. If you have some
> behaviour that could be applied to many different types of objects, you use
> a module and mix it in.
+1
To throw in two other terms: this is inheritance as specialization (or
generalization, if you look the other direction) vs. implementation
inheritance.
> Parent-child inheritance is really just a special case of module inclusion,
> with some extra restrictions. Remember that Class inherits from Module --
> modules are objects that store methods, and classes are objects that store
> methods *and* create new objects.
Absolutely. You can also say: if multiple class inheritance was allowed
classes and modules would have even less distinctive features which
makes it less clear when to choose which. By having more differences
between the two design choices become clearer. My 0.02EUR...
Kind regards
robert