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:
- as an implementor, I have two methods to implement, with probably one calling the other.
- as an implementor, I do not know what is the default value (is it an empty array or the null value ?)
- the documentation for the
GetProperties
is different. Only one states that the method cannot return null. - 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.