接口或抽象类 [英] Interface or Abstract Class

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

问题描述

我想在一个类型中具有3个抽象方法(仅定义且没有实现),我应该使用Interface或Abstract Class作为这3个抽象方法的容器吗?

由于接口和抽象类都可以包含抽象方法,因此我应该在实现中选择一个抽象方法?

"I want to have 3 abstract methods(just definition and no implementation) in a type, should i use Interface or Abstract Class as the container for those 3 abstract methods?

Since Interface and Abstract Class, both can contain abstract methods which one should i choose in my implementation?

推荐答案

请参阅我过去对此主题中引用的主题的回答: 接口问题 [
Please see my past answers on the topic referenced in this one: Doubts on Interfaces[^].

Good luck,
—SA


似乎您最好使用接口
如果您没有成员的任何实现都不需要接口,但是如果您认为将来可能需要任何成员来实现,则该接口是不错的选择.
it seems you''d better go with interfaces
the interface is good if you don''t have any implementation for none of your members but if you think you might need to have any members with implementation in the future, abstract class is a better option.


进入界面,更适合您的情况.
go for interface ,it is better for your scenario.


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

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