Created
October 11, 2020 11:42
-
-
Save zhongyangxun/16fddd303b46eee127fee28eb6f5f4c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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