pyrokinetics.factory.Factory#
- class pyrokinetics.factory.Factory(super_class=<class 'object'>)[source]#
Bases:
object
A variation on the generic ‘factory’ pattern, as defined in the classic ‘Design Patterns’ by the gang of four.
Creates a mapping of keys to types. New types can be ‘registered’ to the factory via a key, and instances of those types can be created by the
create
method by passing that key. Multiple keys can be registered to the same type. Optionally, the factory can only return types derived from a given super class.- Parameters:
super_class (
Type
) – Registered classes must be derived from this type.
Methods
__init__
([super_class])create
(key, *args, **kwargs)Create a new object of type
key
, forwarding all arguments.items
()Dict-like items iterator
register
(key, cls)Register a new type with the factory.
type
(key)Returns type associated with a given key.