Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
By using patterns to manage object creation, we gain flexibility that makes it possible to choose or change the kinds of objects created or used at runtime and to manage object deletion, especially in large software systems. Proper management of the creation of objects is an essential part of managing the separation between layers of code and ensuring the proper disposal of objects at destruction time.
In C++, a factory is a program component, generally a class, that is responsible for creating objects. The idea of a factory is to separate object creation from object usage.