ICollection: a peek under the covers

I just noticed that Robert McLaws blog'ged about an article of mine that he'd recently read.  I remember writing that article a year or so ago now and in it I describe how to create a strongly typed collection that uses abstraction to hide the underlying datatypes.  This is cool because you can easily switch the type that stores lists of data without consumers of your type being affected, yet, you get strongly typed collections that ensure more errors will be picked up at design time (because you're passing less System.Object's all around the place).

Creating Custom Collections
http://www.flws.com.au/showusyourcode/codelib/code/customcollections.asp?CatID=5

After writing that article I headed under the covers to look at what makes a collection "special".  I'd recommend that article for anybody that likes to understand what makes things tick.  For example, how do the following Types differ semantically?: ArrayList, HashTable, Queue, Stack, IDictionary or, even a database index and, how would their underlying data be stored in memory, interested?  Read on...

Creating dynamic data structures
http://www.flws.com.au/showusyourcode/codeLib/code/BinaryTree.asp?catID=5

I love it when people read and comment on stuff that I've written because I mostly write about stuff that I had to spend many hours finding out for myself.  The article titled "Creating dynamic data structures" took me - literally - days of studying and it was only with the help of some very intelligent friends that I actually got that article across the line.  I'd like to publically thank my good friend Bill Wilkinson for the dozens of e-mails that he sent to me that helped me to understand Binary Trees (as opposed to BTrees!).

Finally, having explained how to "roll-your-own" strongly typed collections it's valid to point out that future CLR support for parametric polymorphism and the subsequent implementation of generics by the main languages is going to change a lot of this for language consumers like us!

No Comments