在jax-rs Web服务中使用Java接口的好处? [英] Benifits of using java interfaces in jax-rs web services?

查看:95
本文介绍了在jax-rs Web服务中使用Java接口的好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个Web服务世界很陌生.而且我目前正在探索基于Apache CXF的JAX-RS Web服务.好吧,当我与一些对Web服务有很好想法的前辈交谈时,他告诉我,将接口公开为Web服务而不是实现类始终是一个好习惯.但是我认为我不完全了解这种方法的好处.有人可以解释一下为什么基于接口的方法比常规方法更好吗?

I am very new to this world of web services. And I am currently exploring Apache CXF based JAX-RS web services. Well while talking to some of my seniors who has a pretty good idea of web services, he told me that t is always a good practice to expose an interface as a web service rather than the implementation class. But I don't think I fully understand the benefits of such a approach. Can someone explain me why should a interface based approach be better than a normal approach??

此外,有人可以指向我一个链接,该链接可以向我展示如何从头开始构建基于接口的jax-rs Web服务,而不仅仅是将现有的jax-rs Web服务更改为接口形式.

Also, Can someone point me to a link which can show me how a interface based jax-rs web service is built from scratch rather than just changing a existing one to an interface form.!!

推荐答案

这是OOD的基础之一.这是一个好习惯,因为您将设计与实现分开,例如.

This is one of the base in OOD. This is good practice because you separate design from implementation eg.

现在您有了基于JAX-RS的Web服务.将来您可以拥有 扩展您的JAX-WS实现系统.那你就不用 创建一个新类,但是您基于创建另一个实现 相同的设计(多态).

Now you have WebServices based on JAX-RS. In the future you can have to extend your system of JAX-WS implementation. Then you don't have to create one new class, but you create another implementation based on the same design (polymorphic).

创建松耦合系统时,可以创建灵活的应用程序,易于测试和扩展.

When you create loose coupling system, you can create flexible application, easy to tested and extend.

通过链接: http://dhruba.name/2008/12/08/rest-service-example-using-cxf-22-jax-rs-10-jaxb-and-spring/

这篇关于在jax-rs Web服务中使用Java接口的好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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