开发者

When to use an abstract class? An interface? [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_Go百科

Possible Duplicate:

Interface vs Abstract Class (general OO)

I am little bit familiar with the terms Abstract class and the interface. But i want to know in which situation i have to use the interface and in which condition the abstract class.

Thanks


Interface vs Abstract Class should be a useful read.

In short, Abstract Classes are meant to be extended, as in you're giving someone a base to work off of. Interfaces ensure that things have a common way of interacting with one another without having to worry about the inside details.


Simple answer: you can implements many interfaces, but can only inherit from one class, so if you want to inherit some logic, you should use Abstract Class, otherwise Interface is more extensible.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜