I'm not sure if there is a template that should be used here, but here is the situation:
I have a number of specific classes that implement the interface:
public interface IPerformAction { bool ShouldPerformAction(); void PerformAction(); }
I have another class that checks input to determine if ShouldPerformAction should be executed. Rubbing is that new checks are added quite often. The interface for the validating class is defined as follows:
public interface IShouldPerformActionChecker { bool CheckA(string a); bool CheckB(string b); bool CheckC(int c);
Finally, I currently have specific classes that call each of the validation methods with data specific to that particular class:
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() {
Now every time I add a new check, I have to reorganize specific classes to include a new check. Each particular class passes different properties to the validation method, so subclasses of specific classes are not an option. Any ideas on how this can be implemented in a cleaner way?
c # design-patterns
bmancini
source share