Skip to content

Instantly share code, notes, and snippets.

@korECM
Created July 11, 2020 16:09
Show Gist options
  • Save korECM/b1c97c5d52e321c372f19320b4f62fa7 to your computer and use it in GitHub Desktop.
Save korECM/b1c97c5d52e321c372f19320b4f62fa7 to your computer and use it in GitHub Desktop.
abstract class Beverage {
protected description: string;
private ice: boolean; // 얼름
private mocha: boolean; // 모카
private whip: boolean; // 휘핑
getDescription(): string {
return this.description;
}
protected setIce() {
this.ice = true;
}
protected hasIce() {
return this.ice;
}
protected setMocha() {
this.mocha = true;
}
protected hasMocha() {
return this.mocha;
}
protected setWhip() {
this.whip = true;
}
protected hasWhip() {
return this.whip;
}
abstract cost(): number;
}
class Americano extends Beverage {
constructor() {
super();
this.description = "아메리카노~";
}
cost() {
let baseCost = 4000;
if (this.hasIce()) baseCost += 500;
if (this.hasMocha()) baseCost += 1000;
if (this.hasWhip()) baseCost += 300;
return baseCost;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment