Skip to content

Instantly share code, notes, and snippets.

@rbwestmoreland
Created January 8, 2012 20:34
Show Gist options
  • Save rbwestmoreland/1579576 to your computer and use it in GitHub Desktop.
Save rbwestmoreland/1579576 to your computer and use it in GitHub Desktop.
Properly Implementing the Facade Pattern
using System;
/// <summary>
/// The object which delegates to the appropriate sub-system.
/// <para>The Facade pattern is a structural pattern, whose
/// purpose is to provide a unified interface to a set of
/// interfaces in a subsystem.</para>
/// </summary>
public class Facade
{
#region Property(s)
protected ISubSystemA SubSystemA { get; set; }
protected ISubSystemB SubSystemB { get; set; }
#endregion Property(s)
#region Constructor(s)
public Facade(ISubSystemA subSystemA, ISubSystemB subSystemB)
{
SubSystemA = subSystemA;
SubSystemB = SubSystemB;
}
#endregion Constructor(s)
#region Method(s)
public virtual void ProcessA()
{
SubSystemA.Process();
}
public virtual void ProcessB()
{
SubSystemB.Process();
}
#endregion Method(s)
}
using System;
/// <summary>
/// An interface of a sub-system, which
/// we want to unify.
/// </summary>
public interface ISubSystemA
{
void Process();
}
using System;
/// <summary>
/// An interface of a sub-system, which
/// we want to unify.
/// </summary>
public interface ISubSystemB
{
void Process();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment