I was perusing the TopShelf source code this morning, trying to track down a change in the hosting API, when I discovered that the TopShelf team has succumbed to the new drop the ‘I’ in interface names meme. It’s new to the .NET scene anyway, the java guys have been doing it for a while like all new good ideas in .NET. That were not stolen from ruby anyway.

If you are unfamiliar, the gist of the meme is it is unnecessary to add the ‘I’ in front of an interface name because the consumer of the interface does not care that it is an interface and the ‘I’ is a form of Hungarian notation that the civilized world has all agreed is a bad practice.

So your..

public interface ISomeBehavior { }

..should be..

public interface SomeBehavior { }

And this makes a kind of sense. Where it breaks down is when you see a class that implements the interface that is named like this.

public interface SomeBehavior { }
public class SomeBehaviorImpl { }

I am not quite sure what benefit is in moving the ‘I’ from the interface to the implementation and adding three characters. What have I gained beyond adding to my carpel tunnel? Does my consuming code care somehow that that this is an implementation of some ‘I’-less interface?

At some fundamental level, an interface is a contract. That contract states that the class that implements the interface provides an specific usable set of methods and properties. An other way to look at this is that the interface is a behavior.

Consider the IDisposable interface provided by .NET. There is no DisposableImpl floating around. The interface describes a characteristic of the implementing type, that it behaves like a disposable thing.

Your interfaces need not be a one to one relationship with the implementing class. In fact, your classes can implement multiple SRP friendly interfaces. To quote Brett L. Schuchert:

> class Manager : public ISing, public IDance {}
> 

;-) Keep your interfaces clean, let the managers violate all they want

So, I am sure you making angry face at my blog right now thinking, “Ok, mister smarty pants, what should I do then.”

To that I say, I like the ‘I’, but I use it so that it reads like a declaration.

public interface IReadFiles { }
public interface ICalculateRates { }
public interface ISingAndDance {//OMG SRP VIOLATION!}

And you may find that as preposterous as I find the ‘I’/’Impl’ meme. But that’s cool. To each his own, but that damn ‘Impl’ stuff is not mine.

This post brought to you by Negatron.



blog comments powered by Disqus

Published

26 April 2011

Tags