Monday, December 16, 2013

Abstract Factory Design Pattern

With wider set of available options in the market, applications have to support various protocols at a specific moment in time. It becomes tedious to integrate all such vendors at one go. So to reduce the responsibility of the developer it is mandatory to share the burden with different vendors.

Abstraction has been worked wonderfully for developers and companies in the past. In this pattern too abstraction is the base.

Here, application designates the responsibility of object creation with vendor. Vendor has to write factory to instantiate the object whereas application only uses the reference of the interface.

Using this pattern a framework is defined, which produces objects that follow a general pattern and at runtime this factory is paired with any concrete factory to produce objects that follow the pattern of a certain country. In other words, the Abstract Factory is a super-factory which creates other factories (Factory of factories).

Pic taken from http://howtodoinjava.com/2012/10/29/abstract-factory-pattern-in-java/
As you can see in the image, application wants to decide certain type of cars. So application has provided carfactory interface, which delegates the responsibility on its implementing classes to implement the specific requirement.

As it is evident application has provided default factory, but there are other factories which are defined based on the region i.e. Asia, and US. It can be further divided into different segments i.e. country or class or car.

Advantage of this pattern is the delegating the creation of object on individual vendor.