[Mono-list] ArrayList Enumerator

Nick Drochak ndrochak@gol.com
Tue, 6 Nov 2001 10:33:24 +0900


| > Does an Observer pattern (from GOF) seem
| appropriate?
|
| I am not familiar with the pattern names ;-)  Oops.
|

Indeed, one of the major benefits of the pattern books is that it
establishes a common vocabulary amongst developers. I highly recommend
"Design Patterns" by Gamma, et. al. for this very reason.

| I would think that "broadcasting" an "invalidate" event (an event is just
| a list of delegates in .NET) could be used to tell every enumerator
| "from this point on, you are invalid".  But that seems a bit overkill.
|

<snip code>

|
| This way, we can avoid "broadcasting" messages all the time (which might
| be expensive if we have many listeners and listeners that might be for
| the most part dead).
|

Agreed. This is more of a "pull" model, which in this case might be more
appropriate since the enumerator really doesn't care if the ArrayList is
invalid until it wants to do a MoveNext or such.  Thus we can delay and
minimize any overhead in the ArrayList class to just updating the generation
indicator in the mutators.

I like it!

Thanks,
Nick D.