I have a class library that is responsible for generating reports. Each report consists of the following:

- Header
- Body
- Footer

Some of the reports have the same header / footer. None of the reports have the same body.

The body component is generated by taking a parameter which stores the data that needs to be displayed. The type for the parameter varies for each report.

e.g.  Report 1 might take `List<TypeOne>` as a parameter
       Report 2 might take `List<TypeTwo>` as a parameter

What is the best way to represent the above using a design pattern. I have considered using a factory but am having difficulties with the body section as each report takes different parameters.

Thanks

Is it an option to create a type (class) that contains the available options? Can you provide some more details about the parameters?

What kind of reports are you generating? HTML? Crystal? Some formats will be easier to work with than others for something like this...

Create an IReportData and an IReportGenerator. Use factory to get proper instance of IReportGenerator, and pass proper instance of IReportData to the IReportGenerator you just got.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.