设计模式的问题,我不知道是否有应该在这里使用的模式,但这里的情况是:可维护性
我有许多实现接口的具体类:
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