// トラブル解決の手順 public void DoSupport(Trouble trouble) { if (Resolve(trouble)) { Done(trouble); } else if (next != null) { next.DoSupport(trouble); } else { Fail(trouble); } }
// 未解決 protected virtual void Fail(Trouble trouble) { Console.WriteLine(trouble + " cannot be resolved."); }
// 解決 protected virtual void Done(Trouble trouble) { Console.WriteLine(trouble + " is resolved by " + this + "."); }
// 解決用メソッド protected abstract bool Resolve(Trouble trouble);
// 解決用メソッド protected override bool Resolve(Trouble trouble) { return(trouble.Number == number); }
// 解決用メソッド protected override bool Resolve(Trouble trouble) { return(trouble.Number < limit); }
// 解決用メソッド protected override bool Resolve(Trouble trouble) { return(false); // 自分は何も処理しない }