问题
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