Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is meant by default implementation of an interface

Tags:

c#

.net

interface

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

like image 928
Asad Avatar asked Mar 12 '10 19:03

Asad


People also ask

What is default implementation of interface in Java?

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.

What does it mean to implement an interface?

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.

Do we need to implement default method of 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.


1 Answers

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...

like image 125
Reed Copsey Avatar answered Oct 27 '22 21:10

Reed Copsey