On 10.06.2007 17:38, Gregory Seidman wrote:
> On Sun, Jun 10, 2007 at 07:50:35PM +0900, Robert Klemme wrote:
> [...]
>> It is usually not such a good idea to inherit base classes like Array 
>> and Hash.
> [...]
> 
> That is an interesting statement. I don't think I agree with it, but I'd
> like to hear your reasoning behind it.

This has been discusses numerous times - even here.  On a conceptual 
level basically more often than not a user defined class XYZ /is not/ an 
Array but /uses/ an Array (for storing something).  More practically by 
inheriting Array you conveniently publish all methods you might consider 
useful but you also publish methods that allow for direct Array 
manipulation - which is especially bad if you want to ensure some 
additional constraints (e.g. a certain element order).  While you can 
/unpublish/ methods with Ruby IMHO it is less error prone to explicitly 
define methods that you want to allow on your class.  (Just consider a 
new version of Ruby is available which adds methods to Array that you do 
not want to be available for your clients but which by default /are/ 
available unless you change your code as well.  If you use delegation in 
this case you do not have to do anything about it.

If you disagree then you might be sharing a camp with Bertrand Meyer 
whom I regard highly for his book OOSE, where he also promotes 
implementation inheritance (which you find in Eiffel).  Note though that 
in Eiffel you have more options to control visibility of methods and 
inheritance than in Ruby and the compiler will catch many mistakes you 
can make in this area.

Kind regards

	robert