Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions decorator/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
interface Coffee {
cost(): Number;
cost(): number;
}

class GeneralCoffee implements Coffee {
cost(): Number {
cost(): number {
return 10;
}
}
Expand All @@ -15,25 +15,25 @@ class CoffeeExtraDecorator implements Coffee {
this._coffee = coffee;
}

cost(): Number {
cost(): number {
return this._coffee.cost();
}
}

class BubbleDecorator extends CoffeeExtraDecorator {
private _price: Number = 3;
private _price: number = 3;

cost(): Number {
return super.cost().valueOf() + this._price.valueOf();
cost(): number {
return super.cost() + this._price;
}
}

class MilkDecorator extends CoffeeExtraDecorator {
private _price: Number = 2.5;
private _freshExtra: Number = 1.5;
private _price: number = 2.5;
private _freshExtra: number = 1.5;

cost(): Number {
return super.cost().valueOf() + this._price.valueOf() + this._freshExtra.valueOf();
cost(): number {
return super.cost() + this._price + this._freshExtra;
}
}

Expand All @@ -42,4 +42,4 @@ class MilkDecorator extends CoffeeExtraDecorator {
const withBubble = new BubbleDecorator(general);
const withMilk = new MilkDecorator(withBubble);
console.log(`Total: ${withMilk.cost()}`);
})();
})();