title: Abstract Class in Design Pattern
body: <p>For Facade Design Pattern in the book the book Elements of Reusable Object Oriented Software by Erich Gamma on degign patterns, the implementation part talks about making the facade class an abstract class as it reduces the client and subsystem coupling. </p>
  
  <p>I am not able to understand this point. How can making a class abstract help in reducing the coupling. Somebody please help me in understanding this.</p>
  
  <p><em><strong>Original Code without Facade class as an abstract class:</em></strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Facade_CSharp
  {
      class Program
      {
          static void Main(string[] args)
          {
              Facade facade = new Facade();
  
              facade.ProcessA();
              facade.ProcessB();
  
              // Wait for user
              Console.ReadKey();
          }
      }
  
       /// &lt;summary&gt;
    /// The 'Subsystem ClassA' class
    /// &lt;/summary&gt;
    class SubSystemOne
    {
      public void MethodOne()
      {
        Console.WriteLine(" SubSystem One");
      }
    }
  
    /// &lt;summary&gt;
    /// The 'Subsystem ClassB' class
    /// &lt;/summary&gt;
    class SubSystemTwo
    {
      public void MethodTwo()
      {
        Console.WriteLine(" SubSystem Two");
      }
    }
  
    /// &lt;summary&gt;
    /// The 'Subsystem ClassC' class
    /// &lt;/summary&gt;
    class SubSystemThree
    {
      public void MethodThree()
      {
        Console.WriteLine(" SubSystem Three");
      }
    }
  
    /// &lt;summary&gt;
    /// The 'Subsystem ClassD' class
    /// &lt;/summary&gt;
    class SubSystemFour
    {
      public void MethodFour()
      {
        Console.WriteLine(" SubSystem Four");
      }
    }
  
    /// &lt;summary&gt;
    /// The 'Facade' class
    /// &lt;/summary&gt;
    class Facade
    {
      private SubSystemOne _one;
      private SubSystemTwo _two;
      private SubSystemThree _three;
      private SubSystemFour _four;
  
      public Facade()
      {
          Console.WriteLine("\nRequests received from Client System and Facade is in execution... ");
  
        _one = new SubSystemOne();
        _two = new SubSystemTwo();
        _three = new SubSystemThree();
        _four = new SubSystemFour();
      }
  
      public void ProcessA()
      {
        Console.WriteLine("\nProcessA of Facade uses the following subsystems to accomplish the task:");
        _one.MethodOne();
        _two.MethodTwo();
        _four.MethodFour();
      }
  
      public void ProcessB()
      {
          Console.WriteLine("\nProcessB of Facade uses the following subsystems to accomplish the task:");
        _two.MethodTwo();
        _three.MethodThree();
      }
    }
  }
  </code></pre>
  
  <p><em><strong>Code with Facade class as an Abstract Class:</em></strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Facade_abstract
  {
      class Program
      {
          static void Main(string[] args)
          {
              FacadeAbs facade = new FacadeAbs();
  
              facade.ProcessA();
              facade.ProcessB();
  
              // Wait for user
              Console.ReadKey();
  
          }
      }
  
      class SubSystemOne
      {
          public void MethodOne()
          {
              Console.WriteLine(" SubSystem One");
          }
      }
  
      /// &lt;summary&gt;
      /// The 'Subsystem ClassB' class
      /// &lt;/summary&gt;
      class SubSystemTwo
      {
          public void MethodTwo()
          {
              Console.WriteLine(" SubSystem Two");
          }
      }
  
      /// &lt;summary&gt;
      /// The 'Subsystem ClassC' class
      /// &lt;/summary&gt;
      class SubSystemThree
      {
          public void MethodThree()
          {
              Console.WriteLine(" SubSystem Three");
          }
      }
  
      /// &lt;summary&gt;
      /// The 'Subsystem ClassD' class
      /// &lt;/summary&gt;
      class SubSystemFour
      {
          public void MethodFour()
          {
              Console.WriteLine(" SubSystem Four");
          }
      }
  
      /// &lt;summary&gt;
      /// The 'Facade' class
      /// &lt;/summary&gt;
      public abstract class Facade
      {
          //public abstract Facade();
  
          public abstract void ProcessA();
  
          public abstract void ProcessB();
  
      }
  
      public class FacadeAbs : Facade
      {
          private SubSystemOne _one;
          private SubSystemTwo _two;
          private SubSystemThree _three;
          private SubSystemFour _four;
  
          public FacadeAbs()
          {
              Console.WriteLine("\nRequests received from Client System and Facade is in execution... ");
  
              _one = new SubSystemOne();
              _two = new SubSystemTwo();
              _three = new SubSystemThree();
              _four = new SubSystemFour();
          }
  
  
          public override void ProcessA()
          {
              Console.WriteLine("\nProcessA of Facade uses the following subsystems to accomplish the task:");
              _one.MethodOne();
              _two.MethodTwo();
              _four.MethodFour();
          }
  
          public override void ProcessB()
          {
              Console.WriteLine("\nProcessB of Facade uses the following subsystems to accomplish the task:");
              _two.MethodTwo();
              _three.MethodThree();
          }
  
      }
  }
  </code></pre>
  
  <p><em><strong>Both giving output as:</em></strong></p>
  
  <pre><code>Requests received from Client System and Facade is in execution...
  
  ProcessA of Facade uses the following subsystems to accomplish the task:
   SubSystem One
   SubSystem Two
   SubSystem Four
  
  ProcessB of Facade uses the following subsystems to accomplish the task:
   SubSystem Two
   SubSystem Three
  </code></pre>