This is a simple approach for a factory that makes objects out of dictionaries. The only two ingredients are
- a metaclass
Factory
to manage the class registration and export amake
function - a base class
Creatable
that implements the creation funtion by calling the initializer
The user only has to derive classes from the base class Creatable
and then has access to a dictionary-based creation of instances of such classes.
In the file where Factory.make()
is called, it is necessary to import the Creatable
concrete class otherwise the metaclass initialisation will not run.