Factory vs Abstract Factory Design Pattern

Factory design pattern in C++ is a creational design pattern which deals with creating objects without showing the exact class of object that is being created. This design pattern basically allows a class to defer the instantiation to sub-classes. Below diagram shows a general class diagram of the Factory pattern.

Factory design pattern class diagram

Please look into Factory Design Pattern explanation for more information.

Abstract Factory Design Pattern

The Abstract Factory pattern serves encapsulation to a group of individual factories without exposing the concrete classes. In this model, a generic interface of an abstract factory class is used to create the required concrete object separating the details of implementation of objects from their usage and composition. This design pattern is widely used in GUI applications where similar kind of GUI components needs to be created. Below diagram shows a general class diagram of the Abstract Factory pattern.

Abstract factory design pattern class diagram

Please look into Abstract Factory Design Pattern explanation for more information.

Differences

Factory PatternAbstract Factory Pattern
Objects are being created by Inheritance.Objects are being created by composing different properties.
This method is used to create only one type of object.This method is used to create a family of objects.
In this method, abstract creator is used to create concrete type of object.In this method, concrete factories are used to create object.
Difference between Factory vs Abstract Factory

Leave a Reply

Your email address will not be published. Required fields are marked *