specless.factory.object_factory.ObjectFactory
- class specless.factory.object_factory.ObjectFactory[source]
Bases:
object
Generic object factory leveraging the generic Builder interface see: https://realpython.com/factory-method-python/
Methods
Returns an instance object built with the keyed builder key and the constructor arguments in kwargs
adds the builder object to the internal builder dictionary
- create(key: str, **kwargs)[source]
Returns an instance object built with the keyed builder key and the constructor arguments in kwargs
- Parameters:
key (string) – The _builders dict key reffering to the builder
kwargs (dictionary) – The keywords arguments needed by the builder specified by key
- Returns:
A concrete object built by the builder specified with key
- Return type:
who knows lol
- Raises:
ValueError – given key must match an existing builder in _builders
- register_builder(key: str, builder: Builder) None [source]
adds the builder object to the internal builder dictionary
effects: the _builders dictionary has the key-builder pair appended
- Parameters:
key (string) – The _builders dict key reffering to the builder
builder (Builder) – The Builder object This can be any function, class or object implementing the .__call__() method