2008/9/25 Kyle Schmitt <kyleaschmitt / gmail.com>:
> On Thu, Sep 25, 2008 at 2:26 AM, Robert Klemme
> <shortcutter / googlemail.com> wrote:
>> 2008/9/25 David Masover <ninja / slaphack.com>:
>>> Maybe it's just me, but I often use encapsulation, instead.
>>
>> Same here. In this particular case you need to ensure *all*
>> manipulating methods are overridden in a way that they do not break
>> class invariants (max size for example). Kyle's version for example
>> did not deal properly with #shift, #unshift, #push, #pop, #concat to
>> name a few.
>
> For the moment I was concentrating on the methods I would be currently
> using, and filling it in when I had time. Actually that would be good
> practice to fill it in.
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.
>> Also, since inheritance is a "is a" relationship this could send the
>> wrong message. Can a FixedSizeArray really be used whenever an Array
>> is used? I doubt it.
> 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.
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end