Classes | |
class | Loki::Factory< AbstractProduct, IdentifierType, CreatorParmTList, FactoryErrorPolicy > |
Modules | |
Factory Error Policies | |
Manages the "Unknown Type" error in an object factory. |
The Factory Method pattern is an object-oriented design pattern. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. Factory Method, one of the patterns from the Design Patterns book, handles this problem by defining a separate method for creating the objects, which subclasses can then override to specify the derived type of product that will be created.
More generally, the term Factory Method is often used to refer to any method whose main purpose is creation of objects.
Loki proposes a generic version of the Factory. Here is a typical use.
1. Factory< AbstractProduct, int > aFactory;
2. aFactory.Register( 1, createProductNull );
3. aFactory.CreateObject( 1 );
Product* createProductNull()
{
return new Product
}