Skip to content

Instantly share code, notes, and snippets.

@foo9
Last active December 17, 2015 03:49
Show Gist options
  • Select an option

  • Save foo9/5546543 to your computer and use it in GitHub Desktop.

Select an option

Save foo9/5546543 to your computer and use it in GitHub Desktop.
var VanillaIcecream = (function () {
function VanillaIcecream() {
}
VanillaIcecream.prototype.getName = function () {
return "バニラアイスクリーム";
};
VanillaIcecream.prototype.howSweet = function () {
return "バニラ味";
};
return VanillaIcecream;
})();
var GreenTeaIcecream = (function () {
function GreenTeaIcecream() {
}
GreenTeaIcecream.prototype.getName = function () {
return "抹茶アイスクリーム";
};
GreenTeaIcecream.prototype.howSweet = function () {
return "抹茶味";
};
return GreenTeaIcecream;
})();
var CashewNutsToppingIcecream = (function () {
function CashewNutsToppingIcecream(ice) {
this.ice = ice;
}
CashewNutsToppingIcecream.prototype.getName = function () {
var name = "カシューナッツ";
name += this.ice.getName();
return name;
};
CashewNutsToppingIcecream.prototype.howSweet = function () {
return this.ice.howSweet();
};
return CashewNutsToppingIcecream;
})();
var ice1 = new CashewNutsToppingIcecream(new VanillaIcecream());
var ice2 = new CashewNutsToppingIcecream(new GreenTeaIcecream());
//12. Decorator パターン | TECHSCORE(テックスコア)
//http://www.techscore.com/tech/DesignPattern/Decorator.html/
interface Icecream {
getName() : string;
howSweet() : string;
}
class VanillaIcecream implements Icecream {
constructor() {}
getName() : string {
return "バニラアイスクリーム";
}
howSweet() : string {
return "バニラ味";
}
}
class GreenTeaIcecream implements Icecream {
constructor() {}
getName() : string {
return "抹茶アイスクリーム";
}
howSweet() : string {
return "抹茶味";
}
}
class CashewNutsToppingIcecream implements Icecream {
private ice : Icecream;
constructor(ice: Icecream) {
this.ice = ice;
}
getName() : string {
var name : string = "カシューナッツ";
name += this.ice.getName();
return name;
}
howSweet() : string {
return this.ice.howSweet();
}
}
var ice1 : Icecream = new CashewNutsToppingIcecream(new VanillaIcecream());
var ice2 : Icecream = new CashewNutsToppingIcecream(new GreenTeaIcecream());
//var ice3 : Icecream = new SliceAlmondToppingIcecream(new CashewNutsToppingIcecream(new VanillaIcecream()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment