Skip to content

Instantly share code, notes, and snippets.

@DoRightt
Created June 10, 2020 10:02
Show Gist options
  • Save DoRightt/7ca7c95ee02dd7b061174b3792550ca3 to your computer and use it in GitHub Desktop.
Save DoRightt/7ca7c95ee02dd7b061174b3792550ca3 to your computer and use it in GitHub Desktop.
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