Flyweight API Documentation

class Flyweight[source]

Bases: ABC

Abstract base class that defines the Flyweight interface.

abstractmethod operation(extrinsic_state)[source]

Perform an operation that uses both intrinsic and extrinsic states.

Parameters:

extrinsic_state (str) – The state provided by the client.

Return type:

None

class ConcreteFlyweight(intrinsic_state)[source]

Bases: Flyweight

Represents a Flyweight with intrinsic state that is shared.

Parameters:

intrinsic_state (str)

__init__(intrinsic_state)[source]

Initialize the Flyweight with its intrinsic state.

Parameters:

intrinsic_state (str) – The shared intrinsic state of the Flyweight.

Return type:

None

operation(extrinsic_state)[source]

Perform an operation using both intrinsic and extrinsic states.

Parameters:

extrinsic_state (str) – The state provided by the client.

Return type:

None

class FlyweightFactory[source]

Bases: object

Manages Flyweight objects to ensure they are shared properly.

__init__()[source]

Initialize the factory with an empty pool of Flyweights.

Return type:

None

get_flyweight(intrinsic_state)[source]

Get a Flyweight with the given intrinsic state.

Parameters:

intrinsic_state (str) – The shared intrinsic state of the Flyweight.

Return type:

Flyweight

Returns:

The Flyweight object with the requested intrinsic state.

list_flyweights()[source]

List all Flyweights managed by the factory.

Return type:

None