Abstract Factory

It provides an interface/contract to create family of related objects. (Like an interface for a Factory)

circle-check
circle-check
triangle-exclamation

Explicitly declare interface/class for each distinct object from the same family.

Chair.ts
interface Chair {
    color: string;
    price(): number;
}

class ChairOffice implements Chair {
    color: string;
    price(): number { ... }
}

class ChairTable implements Chair {
    color: string;
    price(): number { ... }
}

Declare the Absctract Factory interface. (This interface has the creation method that returns the abstract type)

Then on each concrete Factory class, the creation method will return the distinct object.

Wherever you use the Factory, you always use the Abstract one.

The distinct Factory will then be injected.

Last updated