class Computer {
cpu: string | null = null;
gpu: string | null = null;
}
interface ComputerBuilder {
buildCpu(): void;
buildGpu(): void;
getComputer(): Computer;
}
class HPBuilder implements ComputerBuilder {
constructor(private computer: Computer) {}
buildCpu() {
this.computer.cpu = "HP cpu";
}
buildGpu() {
this.computer.gpu = "HP gpu";
}
getComputer(): Computer {
return this.computer;
}
}
class DellBuilder implements ComputerBuilder {
constructor(private computer: Computer) {}
buildCpu() {
this.computer.cpu = "Dell cpu";
}
buildGpu() {
this.computer.gpu = "Dell gpu";
}
getComputer(): Computer {
return this.computer;
}
}
class ComputerDirector {
constructor(private builder: ComputerBuilder) {}
build(): Computer {
this.builder.buildCpu();
this.builder.buildGpu();
return this.builder.getComputer();
}
}