Game Development Reference
In-Depth Information
The following code shows how to implement the adapter pattern in C#:
interface Target
{
void DoSomething();
}
class Adaptee
{
public void DoSomethingSpecific()
{
MessageBox.Show(“Hello World!”);
}
}
class Adapter : Target
{
private Adaptee _adaptee = new Adaptee();
public void DoSomething()
{
_adaptee.DoSomethingSpecific();
}
}
class Client
{
public void Run(Target target)
{
target.DoSomething();
}
}
The adapter pattern is not complicated to implement, but can be a great design
move when you run into issues composing legacy components that do not support
the required interface.
Even though there are a number of ways to reduce compositional friction and
improve component cohesion, it was felt that extended coverage of adapters was
important.
When dealing with unmanaged code (legacy components) that must interface
with managed code, the adapter pattern is utilized often, whether explicitly or
Search Nedrilad ::




Custom Search