What design pattern is this?

In the current (C #) project, we have a third-party assembly that contains a non-integrated connection object. Using IoC, etc., we can inject this particular instance into our code, but it proves the nightmare unit test, etc. We use MoQ , because our mocking structure is ideal for interacting with the interface, and we donโ€™t want to go the way of using something like Moles , because we would like to minimize technology.

If we create an interface to simulate the desired functionality of a third-party connection object, and then create an implementer of this interface containing an instance of a third-party object, then this will allow our code to work with the interface, and both our IoC and unit tests will be happy. However, in the discussion, we revolved around what design template it really is!

So the question is: "Is the situation described above and illustrated in the code below:"

  • Adapter , because we provide a wrapper for existing functions.
  • Proxy as we prove the interface for something else.
  • Facade , because as part of the process, we will provide a simplified interface to a larger object.

namespace ExampleCode { public interface IConnector { void Open(); } public class ConnectorWrapper : IConnector { ThirdPartyConnector _instance; public ConnectorWrapper(ThirdPartyConnector instance) { _instance = instance; } void Open() { _instance.Open(); } } } 
+6
oop design-patterns
source share
2 answers

This is certainly a facade. I do this all the time to simplify the redesigned APIs.

+1
source share

Quick response, facade.

From my gof

Adapter:

Converting a class interface to another interface expects clients. The adapter allows classes to work together, which otherwise could not be associated with incompatible interfaces.

It seems that this is not done for reasonable compatibility, you can not say here.

Proxies

Provide a surrogate or placeholder for another object to control access to it.

Do not look good, this is not an access problem.

Facade:

Provide a unified interface for a set of interfaces in the subsystem. The faรงade defines a higher-level interface that simplifies the use of the subsystem.

It looks more like this. You use interfaces to abstract away various implementations, tests, and applications.

+2
source share

All Articles