From: Michael Fellinger Date: 2008-09-26T04:23:07+09:00 Subject: Re: Getting the right class with inheritance and super() On Fri, Sep 26, 2008 at 12:41 AM, Kyle Schmitt wrote: > On Thu, Sep 25, 2008 at 9:51 AM, Robert Klemme > wrote: >> Since I would recommend using delegation instead of inheritance you >> don't have to. If you use inheritance you must make sure that your >> class's invariant is not broken. > > Upon thinking about it more, and attempting to flush it out in the > inheritence direction, I'm coming to agreement about encapsulate > instead. > >>> I'd like it to. This was a first blush since I needed (more wanted, >>> but anyway) it in this project. >> >> If you think about it for a moment you'll realize that your >> FixesSizedArray is far from usable in every place where an Array is >> used. Just think about algorithms that rely on collecting arbitrary >> many objects in an Array (e.g. File.readlines) - you cannot use your >> FixedSizedArray there. > > I agree that it can't be used everywhere, but where I want to use it, > I want it to look and feel very much like an array. > However, the case of File.readlines may be an example of exactly how > I'd like to use it: it gives you a fixed amount of data. > f=FixedSizeArray.new(100) > f< Then the question becomes does the principle of least surprise. Is it > least surprising to read in the first 100 lines, in this case, and > ignore the rest, or is it least surprising to let the 100 line window > slide to the end, and only deal with the last hundred? > > --Kyle