Asad
Asad

Reputation: 21928

what is meant by default implementation of an 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

Upvotes: 8

Views: 1558

Answers (3)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038770

It means that when you call the Sort method without argument (without explicitly specifying a comparer) it will use this default implementation.

Upvotes: 3

Reed Copsey
Reed Copsey

Reputation: 564403

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

Upvotes: 9

Will Marcouiller
Will Marcouiller

Reputation: 24132

This means this class is the one implementing the interface. It points to the object that implements the interface itself without any derived or inherited members, but plainly the interface. This is the class that cirectly corresponds to this interface.

public interface IComparer {
    // Some members to implement here.
}

public class Comparer : IComparer {
    // IComparer members implementation
}

Upvotes: 0

Related Questions