2
0
GGGiovanny Gongora
Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
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();
}
}