gale.factory module

This file contains the class Factory, holding a class (not an instance) and creating new instances of it at a given (x, y) position plus arbitrary extra constructor properties, and AbstractFactory, looking that class up by name within a given module so a Factory can be built from a string instead of importing the class directly.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.factory.Factory(prototype)[source]

Bases: Generic[T]

Parameters:

prototype (T)

create(x, y, properties=None)[source]

Create a new object from the prototype.

Parameters:
  • x (float) – The x component for the position of the object.

  • y (float) – The y component for the position of the object.

  • properties (Dict[str, Any] | None) – A dictionary with the properties that will be set to the new object.

Returns:

A new instance of the prototype.

Raises:

RuntimeError – If the stack is empty

Return type:

T

class gale.factory.AbstractFactory(module_name)[source]

Bases: object

Parameters:

module_name (str)

get_factory(prototype_name)[source]

Build a new factory for the given data type name.

Parameters:

prototype_name (str) – The name of the data type that will be created by the generated factory.

Returns:

The new factory.

Raises:

ValueError – if there is no existing class with the given name.

Return type:

Factory