SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
softPilot.2000 : Software Outsourcing from Ukraine - Site Map SoftPilot.2000 Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net SoftPilot.2000 - Software Outsourcing Ukraine : Software development, Design Patterns. C#. Structural Patterns, C#, dot net
SoftPilot.2000 : Software Outsourcing Ukraine- Home SoftPilot.2000 : Software Outsourcing Ukraine - About SoftPilot.2000 : Software Outsourcing Ukraine - Company Profile SoftPilot.2000 : Software Outsourcing Ukraine - Case Study SoftPilot.2000 : Software Outsourcing Ukraine - Services SoftPilot.2000 : Software Outsourcing Ukraine - Partners SoftPilot.2000 : Software Outsourcing Ukraine - Contacts SoftPilot.2000 : Software Outsourcing Ukraine - E-mail SoftPilot.2000 : Software Outsourcing to Ukraine

SoftPilot.2000 - Software Outsourcing Ukraine.

Software development articles about design patterns implementation in C#.

Structural Patterns.




Facade.

Stuctural design pattern "Facade" used to grant one united inteface for the group of sybsystems. Design pattern "Prototype" is using also like a simple communication interface between subsystems or like an interface between layers in multi-tier application. Anyway, the Facede helps to devide the complex programming system into subsystems and propagate the interfaces between them.

Implementation is simple. We will have the set of internal classes and one front-end facade class which redirect the incoming queryes or just make the front-end interface for subsystems.

In our example we have the complex system represent ( in draft, of course ) the landing gear. The classes "Carriage" and "Casament" are both the internal classes of the system. The "Gear" class is a facade, which taking care about internal parts of the system and propagate the simple interface with two methods: "gear.Remove()" and "gear.Release()".

Let's try to implement this in C#.

 

   
  Facade Pattern, C# implementation:

//Facade design pattern implementation in C#

//------------------------------------
using System;

class Carriage
{
// Fields
  private bool m_isReleased = true;
// Constructors
  public Carriage() {}
// Methods
  public bool Release() { m_isReleased = true; return true; }
  public bool Remove() { m_isReleased = false; return true; }
}

//------------------------------------
class Casament
{
// Fields
  private string m_position = "";
  private bool m_isReleased = true;
// Constructors
  public Casament( string position ) { m_position = position; }
// Methods
  public bool Release() { m_isReleased = true; return true; }
  public bool Remove() { m_isReleased = false; return true; }
}


//------------------------------------
// "Facade"
class Gear
{
// Fields
  private string m_position;
  private bool m_isReleased;

   private Casament l_casament = new Casament("left");
  private Casament r_casament = new Casament("right");
  private Carriage carriage = new Carriage();

// Constructors
  public Gear( string position )
{
  m_position = position;
  m_isReleased = true;
}

// Methods
  public bool Release()
  {
    if (m_isReleased) return true;
    if( !l_casament.Release() ) return false;
    if( !l_casament.Release() ) return false;
    if( !carriage.Release() ) return false;
    m_isReleased = true;
    return true;
  }
  public bool Remove()
  {
    if (!m_isReleased) return true;
    if( !l_casament.Remove() ) return false;
    if( !l_casament.Remove() ) return false;
    if( !carriage.Remove() ) return false;
    m_isReleased = false;
    return true;
  }

//------------------------------------
class FasadeApplication
{
[STAThread]
  static void Main(string[] args)
  {
// Create Facade
  Gear gear = new Gear( "front" );
  if (gear.Remove())
    Console.WriteLine("Gear removed successfully.");
  else
    Console.WriteLine("Warning! Error during gear removing.");

  if (gear.Release())
    Console.WriteLine("Gear released successfully.");
  else
    Console.WriteLine("Warning! Error during gear releasing.");

  Console.Read();
}
}
}


Desigd Pattern Facade. C#.



 
   
(C) SoftPilot.2000 All Rights Reserved. 2000 - 2006