Interface Naming - Anything But Java's Standard, Please
Wednesday, June 14, 2006 at 10:03PM Jeremy dislikes Interface names that being with 'I' ("ISerializable"..). Len Holgate disagrees with him, but likes to name his classes in a "verb-noun" fasion ("IManageUsers").
Personally, I'd much rather have "I" for interfaces. It makes the code much clearer.
Having worked both in Java and C#, I find it very confusing in Java when I keep seeing class names, but I alwasy have this thought in the back of my head "maybe it's really an interface?". And so I have to keep hovering my mouse over the variable types to understand what they really are.
To me, seeing "I" for a type, lets me know that this variable represents something abstract, which its implementation is changeable (I can cast it to other stuff, and send it as a representation of my own stuff).
It lets me understand code which uses lots of dependency injection and realize just what I'm up against.
As for how to name interfaces (the part after the "I"), I like to go with a different rule of thumb than Len's. I name my interfaces as to *what can be done to them*. So a class that implements them suddenly has more abilities to be performed through it. For example, "ISerializable" indicates that the class that implements it supports another operation performed on it.
Len's example states he'd name something "IManageUsers". I'd rather call it "IUserManager" instead, since it is more in the realm of the real implementers of this interface ("UserManager", "DBUserManager" etc.)
It's really a matter of taste and the standard your company employs, but whatever it is, I feel that Java makes it the hardest to comprehend what you're up against. For example, that interface in Java would have been called "UserManager" in the first place, leading to much uglier names such as "UserManagerImp". Ugh.





Reader Comments (3)
4 years later, I still agree, but I am guessing thats just a painful aspect of switching between java and .net.
I do not agree. You point out that seeing the capital I tells you you're dealing with an abstract object, but what about abstract classes then?
Java's naming convention makes good sense, in Java. I agree with the usefulness of prefixing interfaces in C# though as superclasses and interfaces are mixed together.
However, the best convention of interface naming is to give them a name of what they are capable of (Readable, Iterable, etc): Interfaces do not represent actual objects (nouns) but capabilities and should therefor be named as such.
Actually the good thing to have an ugly name for an implementation, such as UserManagerImp or UserManagerImpl, is that you'll feel dirty doing a new of that class, because you shouldn't abuse new in code because you're hardcoding a dependency. Instead those details should be handled by a Dependency Injection container.