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

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.

Replies are listed 'Best First'.
Re^5: An object replacing itself
by diotalevi (Canon) on Sep 23, 2004 at 21:45 UTC
    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.

        That still makes the object a container object. They should only be there if they are intrinsic to the object. If they don't belong to it, they shouldn't be in its possession.