This is a simple approach for a factory that makes objects out of dictionaries. The only two ingredients are
- a metaclass
Factoryto manage the class registration and export amakefunction - a base class
Creatablethat 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.