Re: Getting the right class with inheritance and super()



On Thu, Sep 25, 2008 at 9:51 AM, Robert Klemme
<shortcutter@xxxxxxxxxxxxxx> 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<<File.readlines("/var/log/messages")

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

.



Relevant Pages

  • Re: Getting the right class with inheritance and super()
    ... If you use inheritance you must make sure that your ... FixesSizedArray is far from usable in every place where an Array is ... it gives you a fixed amount of data. ... or is it least surprising to let the 100 line window ...
    (comp.lang.ruby)
  • Re: operator overloading .. more
    ... > will be 25 ints in a contiguous block of memory. ... But inheriting matrix from array is simply wrong. ... > Whenever you use public inheritance, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: operator overloading .. more
    ... > will be 25 ints in a contiguous block of memory. ... But inheriting matrix from array is simply wrong. ... > Whenever you use public inheritance, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Inheritance
    ... What I would like to do is start a league with variables describing the ... Then I would like to start multiple divisions that would be using the time ... What I read about inheritance is that it build on ... but you would not do this to an array item. ...
    (microsoft.public.vc.mfc)
  • Re: operator overloading .. more
    ... will give 5 non-contiguous blocks of 5 contiguous ints. ... But inheriting matrix from array is simply wrong. ... might make sense to use inheritance. ... Whenever you use public inheritance, ...
    (alt.comp.lang.learn.c-cpp)