Created
October 11, 2020 11:41
-
-
Save zhongyangxun/42eb684d82a3f878421bf833b806d9cf 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
interface Computer { | |
run: () => void; | |
} | |
class Windows implements Computer { | |
run() { | |
console.log('Windows') | |
} | |
} | |
class Mac implements Computer { | |
run() { | |
console.log('Mac') | |
} | |
} | |
interface ComputerFactory { | |
product: () => Computer; | |
} | |
class WindowsFactory implements ComputerFactory { | |
product() { | |
return new Windows() | |
} | |
} | |
class MacFactory implements ComputerFactory { | |
product() { | |
return new Mac() | |
} | |
} | |
const macFactory = new MacFactory() | |
const mac = macFactory.product() | |
mac.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment