简体   繁体   中英

design pattern for multi factor processing

I am trying to get a better pattern / technique for this problem:

I have some set of criteria enums say X,Y,Z and I have a process that should produce different outputs/results based on given combinations of the given criteria.

The combinations are defined as a set of rules, for example:

rule_B = new Rule(X.Value1, Y.Value3, z.Value2);
rule_A = new Rule(X.Value2, Y.Value1, z.Value3);

each rule defines a unique combination of the criteria, and not all combinations may have rules (because some combinations may not make sense). The rule instances are not functional they are simply containers to store each factor into a unique combination.

My problem is how do I execute a specific set of processes using a single public interface class, such as:

class RuleExecutor {
    public void ExecuteBasedOnRule(Rule rule) {
        // Here is where I am stuck!!!!!!
    }
}

What sort of design pattern / technique could I use to execute 3 steps 1 for the value of X, one for the value of Y, and one for Z inside the RuleExecutor, each performing a different process based on it's step value. In C++ I would maybe have used template specialization but C# doesn't appear to help me there.

Note: In this convoluted example there are 3 factors with a small set of possible values, in the project I am looking to do these are quite large and creating a concrete class for every possible combination is not something I would consider lightly!

Command pattern seems suitable. You can have 2 steps of execution:

  1. Configure your RuleExecutor with the required Rule .
  2. Run the ExecuteBasedOnRule method of RuleExecutor . The method should parse the stored config and act according to the data.

Thus, I would define an interface with 2 methods: config(Rule) and execute() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM