Command API Documentation

class Command[source]

Bases: ABC

Defines the interface for commands.

abstractmethod execute()[source]

Execute the command.

Return type:

None

class Receiver[source]

Bases: object

Handles the actual business logic for the commands.

action_a()[source]

Executes Action A.

Return type:

None

action_b()[source]

Executes Action B.

Return type:

None

class ConcreteCommandA(receiver)[source]

Bases: Command

Concrete implementation of a command for Action A.

Parameters:

receiver (Receiver)

__init__(receiver)[source]

Initialize the ConcreteCommandA with the specified receiver.

Parameters:

receiver (Receiver) – The receiver instance to operate on.

Return type:

None

execute()[source]

Execute the command by invoking Action A on the receiver.

Return type:

None

class ConcreteCommandB(receiver)[source]

Bases: Command

Concrete implementation of a command for Action B.

Parameters:

receiver (Receiver)

__init__(receiver)[source]

Initialize the ConcreteCommandB with the specified receiver.

Parameters:

receiver (Receiver) – The receiver instance to operate on.

Return type:

None

execute()[source]

Execute the command by invoking Action B on the receiver.

Return type:

None

class Invoker[source]

Bases: object

Stores and executes commands in a sequence.

__init__()[source]

Initialize the Invoker with an empty command queue.

Return type:

None

add_command(command)[source]

Add a command to the queue.

Parameters:

command (Command) – The command to add.

Return type:

None

execute_all()[source]

Execute all commands in the queue and clear it.

Return type:

None