Immutable Collections

I just saw an interesting post that talks about a general pattern of immutable reference types. Good read. I highly recommend it!

At the end of the post the author suggests that we add “value object” generic collection to the BCL. It’s an interesting suggestion, but unfortunately not as easy as it may seem. The difficulty lays in the fact that the items in such collection also need to be immutable. String is an immutable collection of characters, which are immutable themselves.

One way to design this would be to add IImmutable marker interface, implement it on immutable types, and constrain the proposed ReadOnlyList<TImmutable> to TImmutable : IImuttable. Now, I am not sure the value of doing this outweighs the added complexity, but we will take a closer look.