protected override bool Resolve(Trouble trouble) { if (trouble.Difficulty % 2 == 1) { return(true); } return(false); }
public void SupportTrouble(Trouble trouble) { /*递归*/ //if (Resolve(trouble)) //{ // Done(trouble); //} //else if(Next != null) //{ // Next.SupportTrouble(trouble); //} //else //{ // Fail(trouble); //} /*迭代*/ Support current = this; do { if (current.Resolve(trouble)) { current.Done(trouble); break; } else if (current.Next != null) { current = current.Next; } else { current.Fail(trouble); break; } } while (true); }
protected void Fail(Trouble trouble) { Console.WriteLine(trouble.ToString() + " cannot be resolved."); }
protected void Done(Trouble trouble) { Console.WriteLine(trouble.ToString() + " is resolved by " + ToString() + "."); }
protected abstract bool Resolve(Trouble trouble);
protected override bool Resolve(Trouble trouble) { return(false); }