I've been quite busy lately. Both a combination of work and play busy so it's not all bad. Anyway, that's my excuse for not blogging for so long. I've also been neglecting my newsgroups, I should be able to slowly come back online over the next few weeks.
Anyway, I don't have much for this post, merely a little trick I used to simplify my life recently. I had a situation where I had a component, which had numerous child components placed on it. Now, I was really interested in two particular types of these child components, and I wanted to expose them as collections. In order to avoid duplicating code and also to avoid worrying about keeping a collection in sync with the component, I created a ComponentCollection<T> class. You create it, passing in the parent component, and it will then present all child components of type T as if they existed in their own collection.
In reality they don't, I simply use iterators to present a subset of the child components as if they belong to the “collection”. Addition and removal simply add and remove from the parents components collection. I have posted the code at my web site. It's not very efficient, so I wouldn't use it for large component sets, but it certainly saves time and removes all problems of synchronising a collection with the underlying components.
The combination of generics and iterators allow for some very powerful idioms, and some very nice shortcuts. A brilliant example is the Power Collections project. Some of the collections in there got me drooling just coming up with funky ways I could use them. As for the Algorithms class, well, it brings back fond memories of the STL. Happily it doesn't appear to bring back the nasty memories with it.