您将做出抽象类或接口类的决定 [英] What decision will you make Abstract Class or Interface Class

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

问题描述

我应该使用哪个......我的要求会在未来发生变化



抽象类或接口类...您将决定哪个





这是一位受访者提出的面试问题..



答案请

Which should i need to use ...My requirement gets change in Future

Abstract Class or Interface Class...Which will you decide


This is an interview question asked by one of the interviewee..

Answer pls..

推荐答案



[ ^ ]


简答:接口适用于架构师,抽象类适用于编码员。

Long回答:这实际上取决于场景(以及缺少 C#的多重继承)。查看一本好的OOP书,以便区分。
Short answer: Interfaces are for architects, Abstract Classes are for coders.
Long answer: it really depends on the scenario (and on the lack of multiple inheritance of C#). Check out a good OOP book in order to tell the difference.


这不是两种情况:它们是非常不同的野兽。

摘要class是一个几乎完整的类,它要求派生类填充空白,但允许您提供所有派生类共有的代码。

接口没有:它允许您指定实现类必须完成的合同,但是根本不能提供任何代码。



您可以从一个类派生并同时实现一个未指定数量的接口,但是您只能从一个抽象类派生。



它就像Fruit(抽象类)和IDrive(Interface)之间的区别 - 前者允许您派生Apple和Pear类,而后者允许您使用汽车从A到B.从而存在水果; IDrive是一个你无法掌握的过程。
It's not a "either / or" situation: they are very different beasties.
An abstract class is an "almost complete" class that requires the derived class to "fill in the blanks" but allows you to provide code which is common to all derived classes.
An Interface doesn't: it allows you to specify a contract which the implementing class must complete, but which can provide no code at all.

You can derive from a class and implement an unspecified number of interfaces at the same time, but you can only derive from a single abstract class.

It's like the difference between a Fruit (abstract class) and IDrive (Interface) - the former allows you to derive Apple and Pear classes, while the latter allows you to use a car to get from A to B. A Fruit exists; IDrive is a process that you can't hold in your hand.


这篇关于您将做出抽象类或接口类的决定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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