FactoryMethod API Documentation

class Product[source]

Bases: ABC

Abstract base class for products.

This class defines the interface for all concrete products created by the factory method. All subclasses must implement the use method.

abstractmethod use()[source]

Define the behavior of the product.

Return type:

str

Returns:

str – A string describing the product’s behavior.

class ConcreteProductA[source]

Bases: Product

Concrete implementation of the Product interface.

Represents a specific type of product with its own behavior.

use()[source]

Implements the behavior for ConcreteProductA.

Return type:

str

Returns:

str – A string indicating the use of ConcreteProductA.

class ConcreteProductB[source]

Bases: Product

Concrete implementation of the Product interface.

Represents another type of product with its own behavior.

use()[source]

Implements the behavior for ConcreteProductB.

Return type:

str

Returns:

str – A string indicating the use of ConcreteProductB.

class Creator[source]

Bases: ABC

Abstract base class for creators (factories).

Declares the factory method that subclasses must implement to create specific product instances. Provides a common operation that uses the product created by the factory method.

abstractmethod create_product()[source]

Factory method to create a product.

Return type:

Product

Returns:

Product – An instance of a product.

some_operation()[source]

Common operation that uses the product.

Return type:

None

class ConcreteCreatorA[source]

Bases: Creator

Concrete implementation of the Creator class.

Responsible for creating instances of ConcreteProductA.

create_product()[source]

Factory method implementation for creating ConcreteProductA.

Return type:

Product

Returns:

Product – An instance of ConcreteProductA.

class ConcreteCreatorB[source]

Bases: Creator

Concrete implementation of the Creator class.

Responsible for creating instances of ConcreteProductB.

create_product()[source]

Factory method implementation for creating ConcreteProductB.

Return type:

Product

Returns:

Product – An instance of ConcreteProductB.