Skip to content

Instantly share code, notes, and snippets.

@zhongyangxun
Created October 11, 2020 11:42
Show Gist options
  • Save zhongyangxun/16fddd303b46eee127fee28eb6f5f4c2 to your computer and use it in GitHub Desktop.
Save zhongyangxun/16fddd303b46eee127fee28eb6f5f4c2 to your computer and use it in GitHub Desktop.
class Computer {
constructor(mouse: string, keyboard: string, monitor: string) {}
}
class ComputerBuilder {
mouse: string;
keyboard: string;
monitor: string;
addMouse(mouse: string) {
this.mouse = mouse
return this
}
addKeyboard(keyboard: string) {
this.keyboard = keyboard
return this
}
addMonitor(monitor: string) {
this.monitor = monitor
return this
}
build() {
return new Computer(this.mouse, this.keyboard, this.monitor)
}
}
const computer = new ComputerBuilder()
.addMouse('Mouse')
.addKeyboard('keyboard')
.addMonitor('monitor')
.build()
console.log(computer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment