From: "Ara.T.Howard" Date: 2005-07-07T03:14:08+09:00 Subject: Re: Inheriting Array and slice() behaviour On Thu, 7 Jul 2005, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Inheriting Array and slice() behaviour" > on Wed, 6 Jul 2005 18:17:21 +0900, Sylvain Joyeux writes: > > |I have a class inheriting Array, and I expected slice() and [] > |to return Array objects. > > Why? I'd expect them to return instances of the class of the > receiver, as Daniel does in [ruby-talk:147323], since they are ripped > part of the receiver. > > |Moreover, since my Expression class has instance variables, the instance > |produced by slice() does not have it anymore (which is bad) > > I agree that is bad. It might be possible to call initialize() at the > time of sub-array allocation, at the cost of performance. Besides > that, we have to make consensus for how initialize() will be called > for those sub-array. > > Anyway, I'd suggest you not to subclass basic classes, unless you are > sure what you're doing. I don't think Expressions by no means have > is-a relationship to Arrays. Inheritance is not a panacea. you suggest a has-a or aggregation approach then? -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================