问题描述
这可能是一个通用的OOP问题。我想根据它们的用法在接口和抽象类之间进行一般性比较。
This may be a generic OOP question. I wanted to do a generic comparison between an interface and an abstract class on the basis of their usage.
什么时候想要使用界面?何时想要使用抽象类 ?
When would one want to use an interface and when would one want to use an abstract class?
推荐答案
我写了一篇关于此的文章:
I wrote an article about that:
总结:
当我们谈论抽象类时,我们定义了对象类型的特征;指定 对象是什么 。
When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is.
当我们谈论接口并定义我们承诺提供的功能时,我们正在谈论建立一个关于 对象可以做什么的合同。
When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object can do.
这篇关于何时使用接口而不是抽象类,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!