Naming interfaces

Interfaces in .NET have a specific naming convention. They begin with a capital “I”, followed by some text that indicates what the interface represents. IEnumerable is a classic example; it means the implementing object can be enumerated. This naming convention, however, is pretty unique to .NET. In the Java world, interfaces do not have a special prefix to indicate that they are interfaces. Java, unlike .NET, uses two keywords, “extends” and “implements”, to indicate whether a class is participating in an inheritance hierarchy and/or representing some behavior, respectively. In .NET, we use a simple colon and rely on the ordinal position of the class/interface names that come after to indicate the same. The prefix “I” used for interfaces is seen by many (myself included) as unnecessary. It serves no useful purpose other than to provide a visual cues to developers, allowing them to identify interfaces quickly while coding. Java IDEs typically provide these visual cues so that developers don’t have to rely on a naming convention for this purpose. Eclipse example 1 Eclipse example 2 Visual Studio has visual aids as well, but they are not as obvious, in my opinion. I do think a naming convention for interfaces is still a good idea, but I don’t think the prefix “I” is necessary. Instead, I would like to propose that interfaces be named for the behavior that the represent, starting with a prefix like “Can”, or “Will”, or “Has”, followed by a description of that behavior. For example:

  • IEnumerable becomes CanEnumerate
  • IDisposable becomes CanDispose
  • IQueryable becomes CanQuery

Not only is this naming convention more descriptive and less contrived (sometimes it is difficult to come up with an interface name like IXyzable), it forces developers to really think about the behavior they are trying to implement, and may dissuade them from creating interfaces that have nothing whatsoever to do with behavior. (The sudden explosion of IOC mania has obscured the real purpose of interfaces, but that is another topic for another time.)

If you have thoughts on this topic, I’d be interested to hear them.