为什么编程抽象类而不是接口错误? [英] Why is programming to abstract classes instead of interfaces wrong?

查看:92
本文介绍了为什么编程抽象类而不是接口错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将介绍Struts1和Strust2之间的区别,我发现,
Struts 1中的一个常见问题是对抽象类而不是接口进行编程。

I am going through the differences between Struts1 and Strust2 , i found out that , A common problem in Struts 1 is programming to abstract classes instead of interfaces.

有人请让我知道,为什么编程抽象类而不是接口是一个问题?

Could anybody please let me know , Why is programming to abstract classes instead of interfaces is a problem ?

推荐答案



编程抽象类不是问题,这取决于你如何设计对象关系。

Problem?

Programming to Abstract Class is not a problem at all, it is depends how you design your object relationship.

抽象类提供部分实现,促进代码的重用,而Interface仅提供没有任何实现的方法来促进封装。

Abstract Class provide partial implementation, which promote reuse of the code, while Interface only provide methods without any implementation in which promote encapsulation.

当你的子类有某些实现不确定时你应该使用抽象类,其他部分的行为对于所有的子类是相同的。

You should use abstract class when there is certain implementation uncertain to its subclass and other part of the behavior is same for all of the subclass.

这篇关于为什么编程抽象类而不是接口错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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