Abstract Factory Pattern

This pattern comes under creational patterns which are widely used in programming constructs: “This Pattern provide the best way to create the Objects.

Abstract Factory Patternis used to make the Abstract Factory Class (Base-Factory) which is inherited by the Sub Factories class. All objects of the Sub Factories are accessible with the help of the Abstract Factory. The Abstract Factory is sometimes called Factory of Factories (Sub Factories). Only Interface is responsible to create the group of related object without specifying their class. Sub Factories generate the specific Object with the help of interface”.

Explanation (for complete understanding)

Implementations

We have 3 types of vehicle families,



And,



And,

Pros and Cons of the Abstract Factory

  1. Abstract Factory provides the best way of encapsulation in the form of abstract pointer.

  2. Loosely Coupled Application: It means in future we just change the implementation of the base abstract and make the new family by inheriting the base.

  3. Also provides Polymorphism, since we know that inheritance and poly go hand in hand.

  4. The family of the similar objects works together.

  5. When we use the abstract factory all things become much difficult and code is hard to read so this is the issue with the AFP (Abstract Factory Pattern), they enhance the complexity as well.

  6. Due to the loose coupling we make the extra objects which decrease the performance of the application.

Conclusions

Abstract Factory is one of the most usable Design Pattern when we need the higher degree of Abstraction but it is truly dependent upon the needs of the application. If the application architecture needs it, if Application is closed to work with the families of the similar object then we use the Abstract Factory otherwise if we use so they simply enhance the complexity of the applications.