In a current (C#) project we have a 3rd party assembly that contains a non-interfaced connection object. Using IoC, etc we can inject this concrete instance into our code, but it is proving a nightmare to unit test, etc. We are using MoQ as our mocking framework so ideally could do with an interface to work off and we don't want to go down the route of using something like Moles because we would like to minimise technologies.
If we create a interface to mimic desired functionality of the 3rd party connection object and then create an implementor of that interface containing an instance of the 3rd party object then this will allow our code to work off the interface and both our IoC and unit tests will be happy. However in a discussion we've gone around in circles as to which design pattern it really is!
So the question is, "Is the situation described above and illustrated in code below a:"
namespace ExampleCode
{
public interface IConnector
{
void Open();
}
public class ConnectorWrapper : IConnector
{
ThirdPartyConnector _instance;
public ConnectorWrapper(ThirdPartyConnector instance)
{
_instance = instance;
}
void Open()
{
_instance.Open();
}
}
}
Quick answer, facade.
From my GoF
Adapter:
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Doesn't appear to be done for interoperability reason, gonna say no here.
Proxy
Provide a surrogate or placeholder for another object to control access to it.
Don't look good either, it's not an access issue.
Facade:
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
This looks more like it. You're using the interfaces to abstract the different implementations, testing and application.
This is definitely a facade. I do this all the time to simplify over-engineered APIs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With