mercredi 22 août 2018

Structure/Design Patterns for Java parsing program with multiple input combinations based on 2 parameters but one single possible output type

I am writing a tool which takes a file as an input. The input file may be one of these types: "xml", "xlsx", "csv". The file contents will be records of either type "A", "B', or "C". Regardless of input file (xml, xlsx, csv) type or type of record (A, B, C), the program will ultimately produce the same type of output file. Basically no matter what options combination, the resulting file will be a CSV with a specific structure.

I currently have an Interface with one single method "parse(File file)". Then I have 3 classes that implement such interface. Each of these 3 classes are "parser" classes that represent each of the possible file types (xml, xlsx, csv) since they each require a different file reader.

I have a simple Factory design pattern that returns the appropriate Parser class based on the file's extension. Where I am having trouble deciding, is how to deal with the type of record (A,B, or C) after the type of file was dealt with. What is the best way of organizing my classes so that I can have the cleanest structure and where I can reuse the most code possible.

Any ideas would be greatly appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire