Friday, May 19, 2017

(Creational) Abstract Factory Pattern

Abstract Factory Pattern: 
  • Abstract Factory pattern adds another layer of abstraction for Factory pattern.
  • Abstract Factory is a super-factory which creates other factories. We can call it  "Factory of factories".
Interesting points:
  1. Abstract Factory, Builder, and Prototype can use Singleton in their implementation. Abstract Factory Pattern is often used along with Factory Method but also can be implemented using Prototype pattern to increase the performance and simplifying the code.
  2. Abstract Factory can be used as an alternative to Façade pattern to hide platform specific classes
  3. Abstract Factory class declares only an interface for creating the products. The actual creation is the task of the ConcreteProduct classes, where a good approach is applying the Factory Method design pattern for each product of the family.

Difference between Abstract Factory & Factory Method pattern:
  1. Factory Method pattern exposes a method to the client for creating the object whereas in case of Abstract Factory they expose a family of related objects which may consist of these Factory methods.
  2. Designs start out using Factory Method (less complicated, more customizable, subclasses proliferate) and evolve toward Abstract Factory, Prototype, or Builder (more flexible, more complex) as the designer discovers where more flexibility is needed.
  3. Factory Method pattern hides the construction of single object where as abstract factory method hides the construction of a family of related objects. Abstract factories are usually implemented using (a set of) factory methods.
Example: click here












No comments:

Post a Comment