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?

3
  • 1
    What specific problem are you trying to solve? Dec 20, 2016 at 16:20
  • I think it is.. how to handle a poorly designed API. The API is created by a payment operator in my country so it is a real problem.
    – deem
    Dec 20, 2016 at 16:54
  • Possible duplicate of Choosing the right Design Pattern
    – gnat
    Dec 23, 2016 at 14:47

4 Answers 4

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.

3
  • That does sound like a match. Dec 20, 2016 at 17:11
  • By match, Do you mean that both are the same? Could be, depends from the point of view. Gateway also focus on gathering different resources in a single entry point. Independently the quality or complexity of the API hidden behind.
    – Laiv
    Dec 20, 2016 at 17:16
  • I meant that it sounds like the Gateway pattern addresses what the original poster asked about, and does so pretty specifically. In practice, a facade for two APIs is not going to be any different from a gateway, but the description of the Gateway pattern seems more specific to OP's original question. Good answer. Dec 20, 2016 at 18:00
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.

1

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

1
  • without an explanation, this answer may become useless in case if someone else posts an opposite opinion. For example, if someone posts a claim like "I think that you would not use the "Facade Pattern."", how would this answer help reader to pick of two opposing opinions? Consider editing it into a better shape, to meet How to Answer guidelines
    – gnat
    Dec 23, 2016 at 14:46
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.