|
// example of implementing the Facade pattern
using System;
using Concrete;
namespace Concrete
{
public class CEngine
{
public void Start()
{
Console.WriteLine("Starting engine...ok");
}
public void Runup()
{
Console.WriteLine("Performing static runup...ok");
}
public void ThrottleUp()
{
Console.WriteLine("Mixture rich, throttle up");
}
}
public class CAvionics
{
public void SetRadios()
{
Console.WriteLine("Setting radios...ok");
}
public void GetClearance(string s)
{
Console.WriteLine("Getting clearance for " + s + "...");
}
}
public class CControls
{
public void GearUp()
{
Console.WriteLine("Positive rate of climb, gear up.");
}
public void ReleaseBrakes()
{
Console.WriteLine("Releasing brakes...");
}
public void Brake()
{
Console.WriteLine("Braking");
}
public void PitchForTakeoff()
{
Console.WriteLine("Rotate speed reached, nose up");
}
public void PitchForVy()
{
Console.WriteLine("Pitching for best rate of climb.");
}
public void Taxi()
{
Console.WriteLine("Taxiing...");
}
}
public class CFly
{
private CEngine m_oEngine;
private CAvionics m_oRadios;
private CControls m_oControls;
public CFly()
{
m_oEngine = new CEngine();
m_oRadios = new CAvionics();
m_oControls = new CControls();
}
public void Takeoff()
{
Console.WriteLine("Preflight checks and bording complete.");
m_oEngine.Start();
m_oRadios.SetRadios();
m_oRadios.GetClearance("taxi to active runway");
m_oControls.ReleaseBrakes();
m_oControls.Taxi();
Console.WriteLine("Reached runup pad.");
m_oControls.Brake();
m_oEngine.Runup();
m_oRadios.SetRadios();
m_oRadios.GetClearance("takeoff");
m_oControls.ReleaseBrakes();
m_oControls.Taxi();
Console.WriteLine("On centerline, ready to go");
m_oEngine.ThrottleUp();
m_oControls.PitchForTakeoff();
m_oControls.PitchForVy();
m_oControls.GearUp();
}
}
}
namespace Client
{
public class TheClient
{
public static void Main(string[] args)
{
CFly o = new CFly();
o.Takeoff();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
20+ years as a strategist at the intersection of business, design and technology.