Benifits of using java interfaces in jax-rs web services?

£可爱£侵袭症+ 提交于 2020-01-15 03:53:05

问题


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??

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.!!


回答1:


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

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.

With the links: http://dhruba.name/2008/12/08/rest-service-example-using-cxf-22-jax-rs-10-jaxb-and-spring/



来源:https://stackoverflow.com/questions/11427283/benifits-of-using-java-interfaces-in-jax-rs-web-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!