抽象类和接口之间的差异 [英] differance between abstract class and interface

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

问题描述

告诉我抽象类和接口之间的简要区别

tell me the brief differance between abstract class and interface

推荐答案

使用搜索字符串搜索Google/Bing:
抽象类和接口之间的区别"
阅读文章.

如有疑问,请回来.
Search Google/Bing with search string:
"difference between abstract class and interface"
Read the articles.

If you have a doubt, get back.


检查链接以获取详细信息

抽象类与接口 [
Check the Link for Details

Abstract Class versus Interface[^]


Abstract classes可以为其某些成员实现(方法),但是inteface class的任何成员都无法实现.

Interfaces 提供必须由类实现的方法的定义.接口的目的是使您能够概括特定的功能,而与实现无关.您可能具有定义Open()/Close()的IDatabase接口.实现该接口的类可能正在连接到MySQL数据库或MS Access数据库.无论它如何完成此任务,目标都是相同的.
Open database, close database.

Abstract classes是包含一些抽象方法的基类.它们不能被实例化. Abstract类的目的是允许您定义一些通用功能和子类,以在适当的时候实现更具体的功能.

所以我想总结一下.当每个类的实现完全不同时,应使用接口.当您有一些类似的行为但需要以不同的方式实现部分时,请使用抽象类.


请查看以下线程以获取必要的信息:
此CP文章列出了Interface Abstract classes
之间的区别
接口与抽象类之间的差异 [抽象类与C# [抽象类和接口 [ ^ ]
抽象类与接口之间的区别C#.Net [ ^ ]
8差异 [
Abstract classes can have implementations for some of its members (Methods), but the inteface class can''t have implementation for any of its members.

Interfaces provide definitions of methods that must be implemented by a class. The purpose of interfaces is to allow you to generalise specific functionality regardless of implementation. You may have an IDatabase interface that defines Open()/Close(). The class that implements that interface may be connecting to a MySQL database or MS Access database. Irrespective of how it accomplishes this task, the goal is still the same.
Open database, close database.

Abstract classes are base classes that contain some abstract methods. They cannot be instantiated they are to be derived from. The purpose of an Abstract class is to allow you to define some generic functionality and sub-class to implement more specific functionality where appropriate.

So I suppose to summarize. You should use interfaces when the implementation of each class differs completely. Use abstract classes when you have some similar behaviour but need to implement parts differently.


Please have a look on following threads to get some needful:
This CP Article lists the differences between Interface and Abstract classes
Differences Between Interface and Abstract Classes[^]

Difference Between an Abstract Class and an Interface in C#[^]
Abstract class and Interface[^]
Difference between Abstract class and Interface in C# .Net[^]
8-Differences Between Interface and Abstract Class[^]

Hope it helps!


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

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