Factory class

    0

    0

    Giovanny Gongora

    Codiga's TypeScript Recipes

    Create an object without exposing the creation logic to the client and refer to newly created objects using a common interface.

    export interface Product {
      method(param?: any) : void;
    }
    export class ConcreteProductA implements Product {
      method = (param?: any) => {
        return "Method of ConcreteProductA";
      }
    }
    export class ProductFactory {
      public static createProduct(type: string) : Product {
        if (type === "A") {
          return new ConcreteProductA();
        }
        return null;
      }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.