Sunday, March 1, 2009

Interfaces for Collections

http://www.centrifugalbumblepuppy.com/posts/asp-net-collections-interfaces.aspx

For all public properties and method parameters, accept the least restrictive interface.

For all custom collections, implement the most restrictive interface possible.

This means that if a custom collection is in the slightest bit list-like, it should implement IList whenever possible. Conversely, all your methods should accept ICollections, even if this means re-implementing some functionality through static extension classes or decorators.

No comments: