差异黑白抽象类和接口... [英] diff. b/w abstract class and interface......

查看:99
本文介绍了差异黑白抽象类和接口...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手...抽象类和接口都提供相同的功能....
请告诉我一个我们不能使用接口和抽象类的情况,反之亦然.请通过一些真实的例子让我清楚.


在此先感谢

i am new to c#...is both abstract class and interface provide same functionality....
please tell me a situation where we can''t use interface and use abstract class.and vice -versa.Please make me clear with some real world examples.


thanks in advance

推荐答案

请查看我过去的回答:
何时使用抽象以及何时使用接口. ..? [如果抽象类和接口的编号相同,则它们之间的差异方法和var [ ^ ],
如何决定选择Abstract类还是接口 [ ^ ],
接口和多态性 [
Please see my past answers:
When we use abstract and when we use interface...?[^],
Difference between abstract class and interface if they have same no of methods and var[^],
How to decide to choose Abstract class or an Interface[^],
Interfaces and Polymorphism[^].

Also, pay attention for other answers on these pages.

—SA


这就是您的答案- ^ ]

希望对您有所帮助.
-
AP
thats your answer-when will use abstract class and when will use interface[^]

I hope it helped you.
--
AP


虽然您可以使用抽象类和接口实现非常相似的功能,但对我而言,关键的区别是接口只能定义协定,而抽象类不仅可以定义协定,但也可以执行部分​​或全部合同.

我个人的喜好是使用接口来减少应用程序中依赖关系的耦合.当我需要可以从中继承并派生其他更复杂或特定类的共享功能基础时,我倾向于使用抽象类.
While you can achieve very similar things with both abstract classes and interfaces, the crucial difference for me is that an interface can only define the contract whereas an abstract class can not only define a contract, but can also implement some or all of the contract.

My personal preference is to use interfaces to reduce the coupling of dependencies in my application. I tend to use abstract classes when I need a base of shared functionality that I can inherit and derive other more complex or specific classes from.


这篇关于差异黑白抽象类和接口...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆