設計模式的問題,我不知道是否有應該在這裏使用的模式,但這裏的情況是:可維護性
我有許多實現接口的具體類:
public interface IPerformAction
{
bool ShouldPerformAction();
void PerformAction();
}
我有另一個類來檢查輸入,以確定是否應該執行ShouldPerformAction。蹭的是,新的檢查相當頻繁地加入。爲檢查類的接口定義如下:每次
public class ConcreteClass : IPerformAction
{
public IShouldPerformActionCheck ShouldPerformActionChecker { get; set; }
public string Property1 { get; set; }
public string Property2 { get; set; }
public int Property3 { get; set; }
public bool ShouldPerformAction()
{
return
ShouldPerformActionChecker.CheckA(this.Property1) ||
ShouldPerformActionChecker.CheckB(this.Property2) ||
ShouldPerformActionChecker.CheckC(this.Property3);
}
public void PerformAction()
{
// do something class specific
}
}
現在:
public interface IShouldPerformActionChecker
{
bool CheckA(string a);
bool CheckB(string b);
bool CheckC(int c);
// etc...
}
最後我現在有具體的類調用每個特定於該具體類的檢查方法與數據我添加一個新的支票,我必須重新構造具體的類以包含新的支票。每個具體類都將不同的屬性傳遞給檢查方法,所以具體類的子類不是一個選項。關於如何以更清潔的方式實施這些想法的任何想法?
我個人認爲,當前的方法是很乾淨。我們在講多少課?新的支票進來後,真的很難調整必要的具體課程嗎?我認爲不管你如何削減它,你仍然會得到一些你必須調整的具體課程。避免這種情況的唯一方法是在具體類使用的某處執行「CheckAll()」樣式函數。總體而言,我認爲無需調整的性能提高不會超過泥土因素。 – mike 2009-12-16 03:22:45