我们应该在哪里使用INTERFACE&其中ABSTRACT类 [英] Exactly where we should use INTERFACE & where ABSTRACT Class

查看:81
本文介绍了我们应该在哪里使用INTERFACE&其中ABSTRACT类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请准确说明我们应该在哪里使用Interface以及在哪里使用Abstract Class。如果你提供实际的实现,那就太好了。

Please explain exactly where we should use Interface and where to use Abstract Class. Great if you provide practical implementation.

推荐答案

请看我过去的答案:

当我们使用抽象时和使用界面时......? [ ^ ],

抽象类和接口之间的区别,如果它们具有相同的no方法和var [ ^ ],

如何决定选择抽象类或Interf ace [ ^ ],

接口和多态性 [ ^ ],

如何实现界面? [ ^ ]。



-SA
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[^],
How to realize interface?[^].

—SA


您好,



主要抽象和接口之间的区别是



我们在希望子类必须覆盖父类的所有函数的情况下使用抽象类s。



但是在接口的情况下这不是必需的,即如果我们不想覆盖父类的任何函数,我们可以声明接口并继承我们的类它。
Hi,

The main difference between the abstract and interfaces are

We use Abstract classes in the case where we want that the child class must override all the functions of the parent class.

But in the case of Interface this is not necessary i.e if we do not want to override any function of parent class we can declare interface and inherit our class from it.


抽象类:不允许创建实例。

提供基本功能。

重用代码。

可以用来巩固和分享功能

egAnimal是抽象类型,猫,狗,猪是具体类型。



接口:不包含任何逻辑。

也指定类型。

提供不同实例共享的通用功能。
Abstract class : Doesn't allow to create the instance.
Provides basic functionality.
Reuse of code.
Can be used to consolidate and share functionality
e.g.Animal is abstract type and cat,dog,pig are concrete types.

Interface : Doesn't contain any logic.
Specifies type also.
Provides common functionality shared by different instances.


这篇关于我们应该在哪里使用INTERFACE&其中ABSTRACT类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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