Blog Archives
Facade Pattern
Don’t shoot the messenger!
This is something that you are doing all the time. We just name it now. The Facade Pattern is a structural programming design pattern. To explain it in a nutshell:
A class contains many references to objects, which are invisible to the client. The client has a reduced command set to keep things simple.
The class receives the simple command and takes care about the real complexity behind the facade, which is presented to the client. Think of a cash dispenser. All you have to know is a few buttons. The legal structure, the buildings, the accounting, the risk etc. … all is invisible to the client, who only cares about getting cash at this very moment.
namespace FacadePattern { internal class Burger { public void Prepare() { } public void WarmUp() { } public void Wrap() { } } // class internal class Fries { public void Fry() { } public void KeepWarm() { } } // class internal class Drink { public enum eDrink { Coke, SevenUp, Orange, Apple, Milk, Tea, Coffee } public bool IsSugarFree { set; get; } public bool IsHot { set; get; } public void Fill(eDrink xDrink) { } } // class internal class Extras { public void AddSalt() { } public void AddKetchup() { } public void AddMayo() { } public void AddNapkin() { } } // class public class MealFacade { private Burger _Burger = new Burger(); private Fries _Fries = new Fries(); private Drink _Drink = new Drink(); private Extras _Extras = new Extras(); public void MakeClientHappy() { _Drink.IsHot = false; _Drink.IsSugarFree = true; _Drink.Fill(Drink.eDrink.Coke); _Fries.Fry(); _Burger.Prepare(); _Burger.Wrap(); _Extras.AddKetchup(); _Extras.AddSalt(); _Extras.AddNapkin(); } // } // class class Program { static void Main(string[] args) { MealFacade lBurgerMeal = new MealFacade(); lBurgerMeal.MakeClientHappy(); } // main } // class } // namespace