Abstract Factory Pattern

The Abstract Factory Pattern adds another layer of abstraction over the Factory Pattern. It has an Abstract Factory Interface which is implemented by several Factory classes. A Super Factory decides which Factory should be used based on the requirement. Abstract Factory Pattern is one the creational design patterns.

Participants

  • AbstractFactory
    An interface which for creating AbstractProduct objects.
  • ConcreteFactory
    Implements AbstractFactory and creates ConcreteProduct objects.
  • AbstractProduct
    An interface for type of products.
  • ConcreteProduct
    Implements AbstractProduct object. Here is where the actual product code is defined.
  • Client
    Uses methods provided by AbstractFactory and AbstractProduct interfaces to create objects.

 

UML Diagram


Abstract Factory Pattern

As you can see in the diagram, There is an AbstractFactory interface which is implemented by 2 factory classes. Client doesn't access the concrete factory classes directly, instead uses the methods provided by AbstractFactory interface.

Example


Comments

Popular posts from this blog

How to deal with cache stampede in MySQL

Programmer's Guide to Dealing With Different Time Zones

How I learned React.js and Node.js from scratch in a few months