Created
June 10, 2020 10:02
-
-
Save DoRightt/7ca7c95ee02dd7b061174b3792550ca3 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 CaffeineBeverage { | |
final prepareRecipe(): void { | |
this.boilWater(); | |
this.brew(); | |
this.pourinCup(); | |
if (this.customerWantsCondiments()) { | |
this.addCondiments(); | |
} | |
} | |
boilWater(): void { | |
console.log('Boiled water is ready...'); | |
} | |
pourinCup(): void { | |
console.log('Pouring in cup...'); | |
} | |
abstract brew() {} | |
abstract addCondiments() {} | |
customerWantsCondiments() { | |
return true; | |
} | |
} | |
class Tea extends CaffeineBeverage { | |
brew() { | |
console.log('Steep tea bag...') | |
} | |
addCondiments() { | |
console.log('Add lemon...') | |
} | |
} | |
class Coffee extends CaffeineBeverage { | |
brew() { | |
console.log('Dripping coffee through filter...') | |
} | |
addCondiments() { | |
console.log('Add sugar and milk...') | |
} | |
} | |
const tea = new Tea(); | |
const coffee = new Coffee(); | |
console.log('Preparing coffee:') | |
coffee.prepareRecipe(); | |
console.log('Preparing tea:') | |
tea.prepareRecipe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment