What is the best design template for this?

I have a requirement to add a layer between the external library and the client code, so that the client has a consistent interface with the base library, and we can disable the library with minimal code changes.

For instance:

public interface IConsistentInterface { void Foo(string bar); void Bar(string foo); } 

An internally specific implementation of this interface will be called in the library using any functionality that offers. Thus, if we disable the library, we just need to change the internal calls of specific types of this interface.

It looks like an adapter template, but is there a better approach to this problem?

Thanks.

+4
source share
1 answer

It seems that the Gateway template can fit here well. However, as you say, the Adapter pattern may also work well for you. In fact, thinking about it, there seems to be little difference between how the two may look in code.

You cannot go wrong with normalizing an external API in another API that your code can consume sequentially. If changes occur in the external API, the interrupt code will be limited to your normalized API, where you can either fix or limit the damage. The network effect and one of them are aimed at the fact that this is a significantly reduced surface area for the rest of your code.

+4
source

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


All Articles