Skip to content

Instantly share code, notes, and snippets.

@rbwestmoreland
Created December 29, 2011 15:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbwestmoreland/1534639 to your computer and use it in GitHub Desktop.
Save rbwestmoreland/1534639 to your computer and use it in GitHub Desktop.
Properly Implementing the Adapter Pattern
using System;
/// <summary>
/// An actual to expected adapter.
/// <para>The Adapter pattern is a structural pattern,
/// whose purpose is to convert the interface of a class
/// into another interface clients expect.</para>
/// </summary>
public class ActualToExpectedAdapter : IExpected
{
private IActual Instance { get; set; }
public ActualToExpectedAdapter(IActual instance)
{
Instance = instance;
}
public void DoWork()
{
Instance.Process();
}
}
using System;
/// <summary>
/// The actual interface.
/// </summary>
public interface IActual
{
void Process();
}
using System;
/// <summary>
/// The expected interface.
/// </summary>
public interface IExpected
{
void DoWork();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment