Decorator API Documentation

class Component[source]

Bases: ABC

Defines the interface for objects that can have responsibilities added to them dynamically.

abstractmethod get_description()[source]

Get the description of the component.

Return type:

str

Returns:

A string description.

abstractmethod cost()[source]

Get the cost of the component.

Return type:

float

Returns:

The cost as a float.

class ConcreteComponent[source]

Bases: Component

A ConcreteComponent is a base implementation of Component.

get_description()[source]

Returns a string description of the component.

Return type:

str

Returns:

A string representing the description.

cost()[source]

Get the cost of the component.

Return type:

float

Returns:

The cost as a float.

class Decorator(component)[source]

Bases: Component, ABC

Abstract Decorator class that wraps a Component and allows for dynamic behavior addition.

Parameters:

component (Component)

__init__(component)[source]

Initialize the decorator with a component to wrap.

Parameters:

component (Component) – The component to wrap.

abstractmethod get_description()[source]

Get the description of the decorated component.

Return type:

str

Returns:

A string description.

abstractmethod cost()[source]

Get the cost of the decorated component.

Return type:

float

Returns:

The cost as a float.

class ConcreteDecoratorA(component)[source]

Bases: Decorator

Adds specific behavior (Feature A) to the Component.

Parameters:

component (Component)

get_description()[source]

Returns the description of the component with Feature A added.

Return type:

str

Returns:

A string description including Feature A.

cost()[source]

Get the cost of the decorated component with Feature A added.

Return type:

float

Returns:

The cost as a float with Feature A added.

class ConcreteDecoratorB(component)[source]

Bases: Decorator

Adds specific behavior (Feature B) to the Component.

Parameters:

component (Component)

get_description()[source]

Returns the description of the component with Feature B added.

Return type:

str

Returns:

A string description including Feature B.

cost()[source]

Get the cost of the decorated component with Feature B added.

Return type:

float

Returns:

The cost as a float with Feature B added.