C# - Recommendations for Abstract Classes vs. Interfaces
2020-12-13 14:13
标签:c# abstract classes interfaces The choice of whether to design your functionality as an interface or an abstract class can sometimes be a difficult one. An
abstract class is a class that cannot be instantiated, but must be inherited from. An abstract class may be fully implemented, but is more usually partially implemented or not implemented at all, thereby encapsulating common functionality for inherited
classes. An interface, by contrast, is a totally abstract set of members that can be thought of as defining a contract for conduct. The implementation of an interface is left completely to the developer. Both interfaces and abstract classes are useful for component interaction. If a method requires an interface as an argument, then any object that implements that interface can be used in the argument. Abstract
classes also allow for this kind of polymorphism, but with a few caveats:
Here are some recommendations to help you to decide whether to use an interface or an abstract class to provide polymorphism for your components. C# - Recommendations for Abstract Classes vs. Interfaces 标签:c# abstract classes interfaces 原文地址:http://blog.csdn.net/troubleshooter/article/details/40586203
上一篇:关于c++中的类型转换符
文章标题:C# - Recommendations for Abstract Classes vs. Interfaces
文章链接:http://soscw.com/essay/33840.html