Interface和抽象基类有什么不同? [英] What is the different between the Interface and abstract base class?

查看:80
本文介绍了Interface和抽象基类有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接口和抽象基类有什么不同?

抽象基类中的方法无法实现,它与接口中的方法相同。

如果我可以使用抽象基类来实现该功能,为什么我要定义一个接口。

界面的竞争优势是什么?

What is the different between the Interface and abstract base class?
The methods in the abstract base class cannot be achieved, It is as same as the methods in interface.
If I can use the abstract base class to achieve the function, why I do define a Interface.
what is the competitive advantage of the interface?

推荐答案

尝试浏览以下链接 -

摘要类与界面 [ ^ ]

http:// msdn .microsoft.com / zh-CN / library / scsyfw1d%28v = vs.71%29.aspx [ ^ ]

http://codeofdoom.com/wordpress/ 2009/02/12 / learn-this-when-use-an-abstract-class-and-an-interface / [ ^ ]
Try going through the following links -
Abstract Class versus Interface[^]
http://msdn.microsoft.com/en-us/library/scsyfw1d%28v=vs.71%29.aspx[^]
http://codeofdoom.com/wordpress/2009/02/12/learn-this-when-to-use-an-abstract-class-and-an-interface/[^]


两件事:

1)接口根本不能包含任何实现:它的所有方法都是虚拟的。 Abstract类可以包含实际方法,可以在派生类中重写或不重写。

2)您只能从一个基类派生,但您可以根据需要实现任意数量的接口。你不是从一个接口派生出来的,只是来自一个类。
Two things:
1) An interface cannot contain any implementation at all: all it's methods are virtual. An Abstract class can contain real methods, which may or may not be overridden in the derived class.
2) You can only derive from one base class, but you can implement as many Interfaces as you need. You do not derive from an interface, only from a class.


粗略地说,接口只是一个实现类必须遵守的契约。另一方面,抽象类确实提供了一些功能,但是你必须完成它(在派生类中)才能使用它。
Roughly speaking, an interface is just a contract the implementing class has to observe. On the other hand the abstract class does provide some functionality, however you have to complete it (in the derived class) in order to use it.


这篇关于Interface和抽象基类有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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