說我稱之爲方法。我想從該方法返回值。但是,此方法將任務委託給其他方法,而這些方法又可以將任務委派給其他方法。最頂端方法返回的值最終由子方法和子方法的子方法確定。通過方法鏈返回值給調用者
想象一下這樣的情景:
public String method1(Object o){
if(x)
return subMethod1(o);
if(y)
return subMethod2(o);
if(z)
return subMethod3(o);
else
return "";
}
//例如個子方法
public String subMethod1(Object o){
if(a)
return subSubMethod1(o);
if(b)
return subSubMethod2(o);
if(c)
return subSubMethod3(o);
else
return "";
}
//例如subsubmethod
public String subSubMethod1(Object o){
//etc etc
return "";
}
這是一個重複出現的問題,對我來說,我很希望有解決這類問題的設計模式。
有沒有這樣的設計模式?