Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for "Read, Process, Save" pattern?

I'm looking for a desing pattern to solve the following:

Read an Input

Process the data (inc validation)

Save the result

Examples would be: Read a csv file, process the data, save as xml Read an MQ message, process the data, save to database.

I was thinking of a BusinessObject that:

  • Has an IInput implementation to handle reading and loading itself.
  • Can be validated through "rules"
  • Has an IOutput implementation to handle saving itself.

e.g. (pseudo code!)

public abstract class BusinessObject
    {
        public IInput Input { get; set; }
        public IOutput Output { get; set; }

        public BusinessObject(IInput input, IOutput output)
        { }
    }

and then have a Load, Process and Save method.

However, it doesn't seem right to me. I think the BO should be capable of loading and saving itself?

If anyone knows what pattern this might be so I can read up on it, or give me an example/explanation I would be very grateful.

like image 810
BlueChippy Avatar asked Oct 10 '22 09:10

BlueChippy


1 Answers

You could potentially use the Pipeline pattern. In that pattern, you define a chain of components (pipeline components; the chain is then the pipeline) and you feed it input data. Every pipeline component is then executed in turn on the data that is being pushed through the pipe. Any component can read data from and write data to that data.

See also:

  • http://www.codeproject.com/Articles/38799/Pipeline-and-Yield-in-C.
  • C# -Pipeline Style event model
  • http://rantdriven.com/post/Simple-Pipe-and-Filters-Implementation-in-C-with-Fluent-Interface-Behavior.aspx
like image 115
Roy Dictus Avatar answered Oct 13 '22 10:10

Roy Dictus