Click here to Skip to main content
15,893,722 members
Articles / Programming Languages / C#

Illustrated GOF Design Patterns in C# Part III: Structural II

Rate me:
Please Sign up or sign in to vote.
4.90/5 (18 votes)
11 Nov 2002CPOL10 min read 119.7K   578   190  
Part III of a series of articles illustrating GOF Design Patterns in C#
//	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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
United States United States
20+ years as a strategist at the intersection of business, design and technology.

Comments and Discussions