uncategorized

Naming Interfaces and Super (Base) Classes

The number of options when choosing conventions for the naming of interfaces and super classes is fairly limited. Like so many other things in programming, naming of these two things is most effective when the names are clear, meaningful and consistent. These three things will stand out far more than the choice of naming convention or spelling.

Interfaces
Of all the items that I’ll write about in this series, naming conventions for interfaces will be the easiest. I have only ever seen one way of naming interventions in any project that I’ve worked on. Not only that, I can’t find more than one example of an interface naming convention in books or online. As much as most places suggest PascalCasing and camelCasing for all things, including Microsoft (thanks to the Coding Hillbilly for this….I’ll bring a bottle of ‘shine to your place next time we go trapping squirrels), nobody seems to be able to shake the Hungarian Notation recommended for interface naming. The only naming convention ever discussed for interfaces says that all interface names should be prefixed with a capital “I” followed by PascalCasing for the remainder of the name.

1
2
3
4
public interface ICanRefrigerate
{
//some stuff
}

Super (Base) Classes
Naming conventions for super or base classes should follow the same naming convention used for standard classes. The one difference is that you want to make the names of this type of classes both meaningful and useful as suffixes when they are inherited. In the following example you can see how the Car base class works nicely in both the SuperCar and RacingCar classes that inherit from it. The name of the RacingCar class clearly indicates that it is a “type of Car” or inherited from the Car base class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class Car
{
//some stuff
}

public class SuperCar : Car
{
//different stuff
}

public class RacingCar : Car
{
//other stuff
}

My Choices
I’m the first to admit that I didn’t present many options here. In these cases there aren’t many options, no matter how accepted or rejected, to present. I use the “I” prefix for interfaces and I also use the Super/Base class suffixing format as well.