Strategy API Documentation

class Strategy(*args, **kwargs)[source]

Bases: Protocol

Strategy interface that declares a common behavior for all supported algorithms.

execute()[source]

Execute the strategy’s algorithm.

Return type:

str

Returns:

A string result of the algorithm.

class ConcreteStrategyA[source]

Bases: object

A concrete strategy implementing a specific algorithm.

execute()[source]

Execute ConcreteStrategyA’s algorithm.

Return type:

str

Returns:

A string result indicating the execution.

class ConcreteStrategyB[source]

Bases: object

A concrete strategy implementing another algorithm.

execute()[source]

Execute ConcreteStrategyB’s algorithm.

Return type:

str

Returns:

A string result indicating the execution.

class Context[source]

Bases: object

Context class that maintains a reference to a strategy object.

__init__()[source]

Initialize the context without a strategy.

Return type:

None

set_strategy(strategy)[source]

Set the current strategy.

Parameters:

strategy (Strategy) – The strategy to use.

Return type:

None

execute_strategy()[source]

Execute the current strategy’s algorithm.

Return type:

str

Returns:

The result of the algorithm as a string.

Raises:

ValueError – If no strategy is set.