dimanche 30 septembre 2018

Step by step pattern with data transfer between steps

I write simple application which consists of several step. Each step takes its specified input data and produces its specified output. I try to realize such pattern based on pipeline pattern. There are common parts: Interface that each step must realize:

interface IStep
{
    Data Execute(Data data);
}

Interface that must be implemented by class that processes steps:

interface IProcess
{
    void AddStep(IStep step);
    void Run();
}
class Process: IProcess
{
    private List<IStep> steps = new List<IStep>();

    public void AddStep(IStep step)
    {
        steps.Add(step);
    }

    public void Run()
    {
        var data = new Data();
        foreach(step in steps)
        {
            data = step.Ececute(data);
        }
    }
}

Implementation of Data class is the next:

public class Data: Dictionary<string, object> {}

And this is a problem. I have to store key constants for Data and in the beggining of each step extract values required by step. Is there more elegant way to implement such approach?

Aucun commentaire:

Enregistrer un commentaire