Template Methodパターン
Templateの意味
- 「雛型」
Template Methodパターンとは
ソース
namespace TempleteMethod { //スーパークラス public abstract class CaffeineBeverage { protected StringBuilder _recipe = new StringBuilder(); public StringBuilder PrepareRecipe() { this.boilwater(); this.brew(); this.pourInCup(); this.addCondiments(); return this._recipe; } private void boilwater() { this._recipe.AppendLine("お湯を沸かします。/"); } protected abstract void brew(); private void pourInCup() { this._recipe.AppendLine("カップに注ぎます。/"); } protected abstract void addCondiments(); } //サブクラス:コーヒー public class Coffee : CaffeineBeverage { protected override void brew() { this._recipe.AppendLine("フィルタでコーヒーをドリップします。/"); protected override void addCondiments() { this._recipe.AppendLine("砂糖とミルクを追加します。/"); } } //サブクラス:紅茶 public class Tea : CaffeineBeverage { public Tea() { } protected override void brew() { this._recipe.AppendLine("紅茶を浸します。/"); } protected override void addCondiments() { this._recipe.AppendLine("レモンを追加します。/"); } } }
感想
- stringは文字列の配列。charは1文字の配列。デザパタと関係ないけど