I am creating a service that uses a third party API. I do not have control over these classes so just wondered if anything could suggest a pattern to follow that would keep my WCF service contract simple.
The main problem is that the third party API takes in its own types as concrete implementations so its trick to mock these parts of the code. I have started out on the adapter patter route so that I can just give my service contract an interface to use but
I would welcome any other suggestions.
This is a very broad question, but I think the Adapter pattern is a solid choice as it will allow you to wrap the 3rd party API with an
interface. Interfaces are very helpful when it comes to mocking and writing unit tests.
A few more patterns to consider are:
Facade – Simplifies interaction with the 3rd party library by going through some kind of helper class.
Bridge - Define a new intermediate interface between your code and the 3rd party library. This is helpful if the 3rd party library is subject to future changes. Any changes will only affect the one class that communicates with the 3rd party library. The
Bridge Pattern is also good if you have to switch to a different, but similar 3rd party library - again making you only change one class.
Member
2 Points
36 Posts
Pattern for a third party API in my WCF service
Feb 11, 2013 12:24 PM|tonyjoanes|LINK
Hi there
I am creating a service that uses a third party API. I do not have control over these classes so just wondered if anything could suggest a pattern to follow that would keep my WCF service contract simple.
The main problem is that the third party API takes in its own types as concrete implementations so its trick to mock these parts of the code. I have started out on the adapter patter route so that I can just give my service contract an interface to use but I would welcome any other suggestions.
Thanks
Participant
1310 Points
442 Posts
Re: Pattern for a third party API in my WCF service
Dec 13, 2016 03:53 PM|deepalgorithm|LINK
This is a very broad question, but I think the Adapter pattern is a solid choice as it will allow you to wrap the 3rd party API with an interface. Interfaces are very helpful when it comes to mocking and writing unit tests.
A few more patterns to consider are: