in reply to Re^2: An object replacing itself
in thread An object replacing itself

You have better ways to express this sort of thing - a collection should hand these objects out. An object that knows what is "next" already has an implicit collection somewhere otherwise it wouldn't know where it was and what came after it. dragonchild is right and you shouldn't be doing this.

Replies are listed 'Best First'.
Re^4: An object replacing itself
by ryantate (Friar) on Sep 23, 2004 at 21:42 UTC

    Why is a dedicated iterator a better way to get the job done?

    Memory use? Maintainability?

    Why not store the collection inside the object? Am I going to hit trouble down the road?

    I would love to be educated on this. Please tell me why you believe this. Otherwise, I fear I may erroneously conclude it is merely inflexibility/bigotry on your part.

      It is better design. You've separated your concerns when you keep your collection separate from the thing the collection contains. This is a bit like a box that contains other boxes that also contains itself. The primary thing here is to keep the collection object separate from your contained object. Or also, to keep the container out of the things that it contains. You might, if you wished, provide a method on your collection which could do the ->next operation for you.

        None of my objects contains a reference to itself. One object contains a reference to the objects that come after it in a collection. When the next object is loaded, the list is shortened by one and transferred over.