Definition of interface

If inheritance reflects a is-a relationship between a class and its parent, the interface is more a can-be relationship between the class and the code using it.

The interface must be simple but  not simplistic. It must also be unambiguous and favor the ease of implementation. As such, methods overloading must be avoided. Only the most complete method should be declared.

Lets take an example. ICustomTypeDescriptor declares two GetEvents and GetProperties methods, with or without Attribute[] attributes parameter, probably for convenience:

  1. as an implementor, I have two methods to implement, with probably one calling the other.
  2. as an implementor, I do not know what is the default value (is it an empty array or the null value ?)
  3. the documentation for the GetProperties is different. Only one states that the method cannot return null.
  4. because there is two entry in the documentation, the user feedback will be diluted.

The extension methods introduced in the framework 3.5 are very advantageous because you can now have both the ease of use and the ease of implementation. It makes also more sense for a user to provide feedback on the interface itself than on the helper.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.