views:

65

answers:

3

I'm writing a web application that needs to export data out of it. The problem is that every client requires a different format. Some want tab delimited, some comma seperated and even fixed width.

Different data may also be needed by each export.

What approaches should i consider to make it so that each client can have their own format?

+1  A: 

I would create a class which retrieves the data that you're interested in.

I would also create a class (or set of classes) which contains / represents the data that you have retrieved.

Then, I think I would create an interface or abstract base-class 'Printer' or 'Formatter', or whathever name is suitable, which would be responsible for formatting the data into the desired format. You could then create specific subclasses which implement the logic that is required to put the data in the correct format.

Frederik Gheysels
A: 

Check out the Strategy Pattern

Patrick McDonald
+1  A: 

I needed the same requirements as you.

here are some links to the questions that helped me get this design pattern implemented I guess it's a mix between the strategy pattern and the observer pattern

If you wanted you could easily do without reflection if you are going to store all of the "Formatters" in the same assembly. You can just store the class name in the clients configuration, and then create your formatter object depending on which class the client has configured.

http://stackoverflow.com/questions/651283/reflection-application-design
http://stackoverflow.com/questions/639911/inheritance-events

if you need a working example i can post one in the morning.

Michael G