Assuming I'm using a class from third party library that does not implement an interface, for example:
class ThirdPartyLibClass {
void DoThis() { ... }
void DoThat() { ... }
}
I want to create a very thin wrapper around it, directly reflecting class' interface and delegating to the ThirdPartyLibClass
. The purpose of this is to stub ThirdPartyLibClass
in my unit tests. Example:
interface IThirdPartyLibClass {
void DoThis();
void DoThat();
}
class DefaultImplementation : IThirdPartyLibClass {
private ThirdPartyLibClass realImplementation = new ThirdPartyLibClass ();
void DoThis() {
realImplementation.DoThis();
}
void DoThat() {
realImplementation.DoThat();
}
}
Is there a name for this pattern? Wrapper or Adapter seem to differ slightly, and I don't intend to ever swap the implementation in production code, so the interface is exactly the same as that of ThirdPartyLibClass
. Also, how would I call the DefaultImplementation
to make the pattern usage clear to the reader?
Thanks in advance.
DefaultImplentation
just delegates all API calls directly to the lib, I don't know a shorter term to describe this.