Skip to content

Commit 8099eff

Browse files
committed
Modify Decorator code
1 parent 22391c2 commit 8099eff

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

Decorator/Beverage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Beverage = function()
33
this.sDescription = 'Unknown beverage';
44
};
55
Beverage.prototype.getDescription = function(){
6-
return this.sDescription;
6+
throw new Error("This method must be overwritten!");
77
};
88
Beverage.prototype.cost = function()
99
{

Decorator/CondimentDecorator.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ var CondimentDecorator = function()
22
{
33
Beverage.apply(this);
44
};
5-
CondimentDecorator.prototype.getDescription = function()
6-
{
7-
throw new Error("This method must be overwritten!");
8-
};
5+
CondimentDecorator.prototype = new Beverage();

Decorator/Expresso.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var Expresso = function()
22
{
3+
Beverage.apply(this);
34
this.sDescription = 'Expresso';
45
};
6+
Expresso.prototype = new Beverage();
57
Expresso.prototype.cost = function()
68
{
79
return 1.99;

Decorator/HouseBlend.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var HouseBlend = function()
22
{
3+
Beverage.apply(this);
34
this.sDescription = 'House Blend coffe';
45
};
6+
HouseBlend.prototype = new Beverage();
57
HouseBlend.prototype.cost = function()
68
{
79
return 0.89;

Decorator/Mocha.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Mocha = function(oBeverage)
33
CondimentDecorator.apply(this);
44
this.oBeverage = oBeverage;
55
};
6+
Mocha.prototype = new CondimentDecorator();
67
Mocha.prototype.getDescription = function()
78
{
89
return this.oBeverage.getDescription() + ", Mocha";

0 commit comments

Comments
 (0)