I have seen this statement in many of the documention samples, like here
This class is the default implementation of the "ISomeInterface" interface
what exactly this means ? Thanks
Default Interface Methods Defined Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. and then proceeds to supply a convoluted, 50+ line example.
An Interface is a specification of functionality that a class MUST implement. When you implement an interface, you are specifying to any consumers of your class that you supply the functionality defined in the given Interface.
Default interface methods are an efficient way to deal with this issue. They allow us to add new methods to an interface that are automatically available in the implementations. Therefore, we don't need to modify the implementing classes.
This is somewhat misleading, since an interface, by definition, provides no implementation.
However, many portions of the framework try to make life easier - so they provide a method which takes an interface, but also provides an overload with no parameters. A good example is List<T>.Sort
.
The documentation here is suggesting that, if you use a method that would normally require an IComparer<T>
, but use it via some overload that doesn't, you'll get the referenced "default implementation" used instead.
However, this is really an "implementation detail" of classes unrelated to the interface itself. I personally think this is a poor choice of words in the documentation, and should be something more like:
Many types in the framework rely on a common implementation of this interface provided by the Comparer class.
This would, in my opinion, provide a more clear meaning to this...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With