Design Pattern for importing data
Which Design Pattern I can use to implement the import of data in different formats, such as, XML, CSV, TXT, XLSX etc...
Imran Khan, Jul 29, 2010
This can be done with a combination of various patterns. First try to classify what varies in the application. For e.g. the data-source (it could be xml, csv, excel) anything. Abstract those variation. Just to cite an e.g. you can use a "factory" for controlling object creation and a strategy for separating out the parsing of different file stores(or may be a provider pattern can play a role here). Other patterns may as well be adopted.
To see a live example in action visit http://www.codeproject.com/KB/database/filehelpers.aspx. Though this article doesn't mention directly anything about design patterns but the code is very well organized and may be a good learning as well.
Rajesh Pillai, Jul 31, 2010
First of all, I believe you should ask the other way around: What exactly do I want to achieve? Whether or not there are design patterns that can help you to prevent common problems to arise will be the next question.
As I understand you have data in different formats available but a common way to work with it in your application (e.g. a DataTable with a given structure). You already know that you don't have only a txt file with a specific format but also xml, csv and other files. At some point you may also have even more file formats or other source structures.
Christian Jacob, Jul 30, 2010