Skip to content

Instantly share code, notes, and snippets.

@zhongyangxun
Created October 11, 2020 11:41
Show Gist options
  • Save zhongyangxun/42eb684d82a3f878421bf833b806d9cf to your computer and use it in GitHub Desktop.
Save zhongyangxun/42eb684d82a3f878421bf833b806d9cf to your computer and use it in GitHub Desktop.
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