I'm trying to figure out the correct design pattern to use for a sequence of operations that execute one after another before producing a final output. The output of each function feeds into the next function (along with some external inputs) and so on. The type of operations and the orders in which they'll be applied are not fixed and must come from a configuration database/file.
For example - Consider a system that formats and manipulates a raw file before storing it in the database. The system will have the following components -
- A configuration database that stores the operations to apply, order of application and any optional parameters related to those operations. Operations can be anything, for example, "Remove whitespaces" or "Multiply by 2" or "Replace x with y" or "do some complicated financial calculation", basically any generic function where output = f(filedata, staticdata1, staticdata2...).
- A system that reads the file and reads the configuration database and is able to correctly identify, queue and then apply the operations in the correct order and validate inputs and outputs.
With that setup in mind, we're looking at the following algorithm -
- Step 1 - For each line in the file, execute next steps.
- Step 2 - Find the first operation from the configuration db.
- Step 3 - Validate the file data and apply the operation. Store the output in a variable.
- Step 4 - Find the next operation from configuration db.
- Step 5 - Repeat step 3 with the operation read in step 4 and output of step 3.
So, ultimately it's basically a couple of loops and a switch. But are there any established design patterns that deal specifically with this scenario? Or C# language features (like expression trees or whatever) that can help with implementation?
Aucun commentaire:
Enregistrer un commentaire