title: How does Abstract Factory uses delegation
body: <p>The difference between Abstract Factory and Factory design pattern is that AbstractFactory pattern uses composition to delegate responsibility of creating object to another class while Factory design pattern uses inheritance and relies on derived class or sub class to create object.</p>
  
  <p>Below is a typical example of an abstract factory(<a href="http://www.oodesign.com/abstract-factory-pattern.html" rel="nofollow">http://www.oodesign.com/abstract-factory-pattern.html</a>) Could some one please explain me where the abstract factory is using object composition?</p>
  
  <pre><code>abstract class AbstractProductA{
  public abstract void operationA1();
  public abstract void operationA2();
  }
  
  class ProductA1 extends AbstractProductA{
      ProductA1(String arg){
          System.out.println("Hello "+arg);
      } // Implement the code here
      public void operationA1() { };
      public void operationA2() { };
  }
  
  class ProductA2 extends AbstractProductA{
      ProductA2(String arg){
          System.out.println("Hello "+arg);
      } // Implement the code here
      public void operationA1() { };
      public void operationA2() { };
  }
  
  abstract class AbstractProductB{
      //public abstract void operationB1();
      //public abstract void operationB2();
  }
  
  class ProductB1 extends AbstractProductB{
      ProductB1(String arg){
          System.out.println("Hello "+arg);
      } // Implement the code here
  }
  
  class ProductB2 extends AbstractProductB{
      ProductB2(String arg){
          System.out.println("Hello "+arg);
      } // Implement the code here
  }
  
  abstract class AbstractFactory{
      abstract AbstractProductA createProductA();
      abstract AbstractProductB createProductB();
  }
  
  class ConcreteFactory1 extends AbstractFactory{
      AbstractProductA createProductA(){
          return new ProductA1("ProductA1");
      }
      AbstractProductB createProductB(){
          return new ProductB1("ProductB1");
      }
  }
  
  class ConcreteFactory2 extends AbstractFactory{
      AbstractProductA createProductA(){
          return new ProductA2("ProductA2");
      }
      AbstractProductB createProductB(){
          return new ProductB2("ProductB2");
      }
  }
  </code></pre>
  
  <p>As for as I understood subclass's <code>ConcreteFactory1</code> and <code>ConcreteFactory1</code> are returning object's to the client. And its typically working as a Factory class with more than one product.</p>
  
  <p>Where as Client code could be</p>
  
  <pre><code>AbstractFactory factory = new ConcreteFactory2();
  AbstractProductA prodA = factory.createProductA();
  </code></pre>
  
  <p>Could some one please explain me where does the Object composition/delegation happen in the Abstract Factory?</p>