4

I need to work with some payment gateway API. The API is divided into two parts. There are some methods based on REST and a few methods accessible through SOAP webservice. I would like to create some bridge to combine it into single API class in my application. However I am not sure it is a good choice. The question is.. is there any design pattern for this kind of situations?

deem
  • 207
  • 1
  • 6

4 Answers4

4

I would suggest Gateway

The difference is that Gateway hides external API complexity to your internal API.

Facade, seems to me the opposite. Hides your complexity to external clients.

In both cases the implementation is similar.

Laiv
  • 14,990
2

As @user1172763 mentioned this is called a Facade. A facade is usually used to provide a simplified interface for a more complex system. But as the wiki link mentions, a Facade is also used to:

wrap a poorly designed collection of APIs with a single well-designed API.

In this case you hide two heterogenous APIs (one REST, one SOAP) behind a homogenous (facade) API.

Bogdan
  • 3,650
1

Not much of a pattern nerd, but I think that you would use the "Facade Pattern."

1

And in addition to using the Facade pattern, and if you want to get more elegant and pure with your code, I would recommend using the Adapter pattern to cleanly convert the interface of the outer API classes to what is expected for the inner API classes.