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. General class diagram of Factory pattern is shown below.
Please look into Builder design pattern 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. General class diagram of Abstract Factory pattern is shown below.
Please look into Abstract factory design pattern for more information.
Differences between Builder vs Abstract factory design pattern
Builder method | Abstract factory method |
---|---|
In this method, a Director class is used to Builder class about the creation of various parts of the object and returns the object. | In this method, object created are returned directly from the factory class. |
This method has the reference of the created object. | This method doesn’t have the reference of the created object. |