Wednesday, February 14, 2007

Interface Naming Guidelines

- Should name the interface with noun or noun phrase or adjective that describes its behavior.
For example: The interface name IComponent uses a descriptive noun. The interface name ICustomAttributeProvider uses a noun phrase. The name IPersistable uses an adjective.
- Should use Pascal case for interface name
- Use abbreviations carefully
- Should prefix interface name with the letter “I” to indicate that it’s of type interface.
- Use similar names when you define a class/interface pair where the class is a standard implementation of the interface. The names should differ only by the letter I prefix on the interface name.
For example: ICalculator is interface and related class could be Calculator
- Should NOT use the underscore character "_"


The following are examples of naming interfaces:

public interface IServiceProvider
public interface IFormatable


Following code illustrates how to define an interface IComponent and its standard implementation, the class Component.

public interface IComponent
{
// Interface code goes here.
}

public class Component: IComponent
{
// class Implementation code goes here.
}

No comments:

Post a Comment