export interface Prototype {
        clone(): Prototype;
        toString(): string;
      }
      export class Concrete1 implements Prototype {
        clone() : Prototype {
          return new Concrete1();
        }
        toString(): string {
          return "This is Concrete1";
        }
      }
      export class Builder {
        private prototypeMap: { [s: string]: Prototype; } = {};
        constructor() {
          this.prototypeMap['c1'] = new Concrete1();
        }
        createOne(s: string): Prototype {
          console.log(s);
          return this.prototypeMap[s].clone();
        }
      }
      
      Typescript language logo

      Prototype Class

      Codiga's TypeScript Recipes

      Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.