High Interface diet

As long as I'm on the coding conventions track (as many of users have commented on my last post), I'll talk about a small coding convention I am trying to do.

 

I feel more compelled to push an interface into a property, method, or any declaration rather than an object type. Why push around List<string> when you can push around IList<string>? It seems like a much better design decision. It also seems that there is more flexibility as far as future extensions are concerned.

 

Come on, let's hear those thoughts :)

Published Monday, March 10, 2008 9:54 PM by zowens

Comments

# re: High Interface diet

Sunday, March 16, 2008 9:08 PM by Brian Lowry

There is no doubt that passing around interfaces is better for long-term versioning. I use the interface versions (especially IList) all over the place.

Given the enhancements being made in each version of .NET, it really doesn't make much sense not to support future implementations of IList but to tie yourself down to a concrete class like List.

Given that, Resharper 4.0 has made life much easier as it can determine if the interface you using as a method parameter is fully utilized. Sometimes it will recommend I  "downgrade" IList to IEnumerable if I'm only using methods  that the two share (the enumerator).

Leave a Comment

(required) 
(required) 
(optional)
(required)