开发者

what is meant by default implementation of an interface

I have seen this statement in many of the documention samples, like h开发者_Go百科ere

This class is the default implementation of the "ISomeInterface" interface

what exactly this means ? Thanks


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


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


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜