Struts 2 使用接口,而 Struts1 使用类
我正在阅读有关 Struts1 与 Struts2 的文章,作者提到其中一点是
“对抽象类而不是接口进行编程是 struts1 框架的设计问题之一,该问题已在 struts 2 框架中得到解决。大多数 Struts 2 类都是基于关于接口 “
从开发人员的角度来看,有人可以告诉我,我们是否需要关心框架是否使用类或接口。 有人可以帮助我了解为什么在界面中使用类不好。
I was reading about Struts1 vs Struts2 and the author mentions one of the point is
" Programming the abstract classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework. Most of the Struts 2 classes are based on interfaces "
COuld anybody please tell me , from a developer point of view , does we need to bother if the framework uses classes or interfaces .
Could anybody please help me in knowing why using Classes in a interface is not good .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是这么说的。
请参阅此问题/答案,或搜索网络“编程到接口”。简而言之,对接口进行编程(如果正确完成)允许我们根据需要使用该接口的多个实现。
这样做可以让我们更轻松地进行测试,允许我们在编写原始基本代码时(在合理范围内)时不一定想到的功能,等等。
That's not what's said.
See this SO question/answer, or search the web for "program to an interface". The nutshell version is that programming to an interface (when done correctly) allows us to use multiple implementations of that interface based on our needs.
Doing so allows us to test more easily, allow functionality we didn't necessarily think of when we wrote the original base code (within reason), and so on.