@tusss/ood
    Preparing search index...

    Class FactoryDirector<TProduct>Abstract

    Abstract base class for orchestrating multiple factories based on material types.

    Keeps a registry (cluster) mapping material type strings to their respective factory constructors, allowing dynamic product instantiation based on material input.

    Example demonstrating factory orchestration with Materials A/B and Product

    type TMaterialType = "A" | "B";

    class MaterialA extends FactoryMaterial<TMaterialType> {
    override readonly type: TMaterialType = "A";
    }
    class MaterialB extends FactoryMaterial<TMaterialType> {
    override readonly type: TMaterialType = "B";
    }

    class Product {
    constructor(readonly name: string) {}
    }

    class FactoryA extends Factory<Product> {
    override create(): Product {
    return new Product("A");
    }
    }
    class FactoryB extends Factory<Product> {
    override create(): Product {
    return new Product("B");
    }
    }

    class Director extends FactoryDirector<Product> {
    override cluster = new Map<TMaterialType, new (material: FactoryMaterial) => Factory<Product>>([
    ["A", FactoryA],
    ["B", FactoryB],
    ]);
    }

    const director = new Director();
    const productA = director.create(new MaterialA()); // Product { name: "A" }

    Type Parameters

    • TProduct

      The type of products created by the registered factories.

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    cluster: Map<string, new (material: FactoryMaterial) => Factory<TProduct>>

    Map containing factory constructor associations keyed by material type name.

    Methods

    • Orchestrates the creation of a product. Looks up the appropriate factory class based on the input material type, instantiates it with the material, and builds the product.

      Parameters

      • material: FactoryMaterial

        The material input to determine which factory to run.

      Returns TProduct

      The constructed product of type TProduct.

      Error If no factory has been registered for the given material type.