Design a template for working with different versions of web services?

I am looking for a design template to solve an architectural issue that I have.

I use some web services that are the same, but not quite. Several more methods may be available for each new version of web services, but for the most part they are basically the same.

I want to write abstractionlayer, which works regardless of the version of web services that I communicate with. Obviously, if I use a method that exists only in newer versions of web services, I will get some kind of error, but this is normal. I can handle them.

The reason I want this level of abstraction is to avoid the hard link between my application and the version of web services it exchanges with.

What are my options when it comes to design patterns for my level of abstraction? I see that there is one template called “Adapter” and the other is “Bridge”. Do any of them do this in this situation? Any help is appreciated!

Edit - for clarity, here is a drawing. enter image description here

Sometimes I want my application to talk to webservices version 1, and sometimes I want it to use webservices version 2. It depends on who uses the client application.

The client application does not have to know or care about which version it is talking to. The only exception is that if he uses a method available only in some versions, I need to handle it gracefully (tell the user that they installed the old version of web services).

+4
source share
2 answers

It will be a factory. You can even use the built-in ChannelFactory or come up with your own. In any case, the information system allows you to change the implementation without changing the client contract.

+2
source

I suggest using the FACADE pattern. You can follow the link below to find out more about this. http://javapapers.com/design-patterns/facade-design-pattern/

The façade should provide an abstraction and a seamless layer for customer interaction. It hides all the internal difficulties, since in your case the client must find the correct version of the web service with which he can interact. Suppose you have a different version of web services and the input structures json / xml have changed in different versions. The facade will receive a client call, it will check the input for different versions of web services, and then call the correct version of the web service. If you don’t have a façade layer, then the client will have to fight for the correct version of the webservice, and he will need to send several calls before reaching the correct web service.

+2
source

Source: https://habr.com/ru/post/1479151/


All Articles