Builder API Documentation

class Product[source]

Bases: object

Represents the complex product being built.

The Product class contains attributes part_a and part_b, which represent the individual parts of the product. It provides methods to set these parts and a string representation to display the constructed product.

__init__()[source]

Initializes the Product instance.

Sets the attributes part_a and part_b to None, which represent the individual parts of the product.

set_part_a(part_a)[source]

Sets Part A of the product.

Parameters:

part_a – A string representing Part A of the product.

set_part_b(part_b)[source]

Sets Part B of the product.

Parameters:

part_b – A string representing Part B of the product.

class Builder[source]

Bases: ABC

Abstract interface for constructing a Product.

Defines methods for building different parts of a product and retrieving the final constructed result.

abstractmethod build_part_a()[source]

Builds Part A of the product.

abstractmethod build_part_b()[source]

Builds Part B of the product.

abstractmethod get_result()[source]

Retrieves the constructed product.

Return type:

Product

Returns:

The constructed Product instance.

class ConcreteBuilder[source]

Bases: Builder

Concrete implementation of the Builder interface.

Constructs a specific type of product by implementing the building steps defined in the Builder interface.

__init__()[source]

Initializes a new instance of the ConcreteBuilder class.

Initializes the builder with a new instance of the Product class.

build_part_a()[source]

Builds Part A of the product.

Sets Part A to a specific value defined by this builder.

build_part_b()[source]

Builds Part B of the product.

Sets Part B to a specific value defined by this builder.

get_result()[source]

Retrieves the constructed product.

Return type:

Product

Returns:

The fully constructed Product instance.

class Director(builder)[source]

Bases: object

Orchestrates the construction process.

The Director class uses a Builder to construct a Product in a predefined sequence.

Parameters:

builder (Builder)

__init__(builder)[source]

Initializes the Director with a builder.

Parameters:

builder (Builder) – The Builder instance to use for constructing the product.

construct()[source]

Constructs the product by invoking the builder’s methods in sequence.

get_product()[source]

Retrieves the constructed product from the builder.

Returns:

The constructed Product instance.