0

I have a versatile custom object converter which should be able to,

  • read from XML and write to XML
  • read from XML and write to CSV
  • read from CSV and write to XML
  • read from CSV and write to CSV

So, I thought I could do smth like :

Converter
{
 IReader reader;
 IWriter writer;
}
IReader
{
 read();
}

..(same for writer) then instantiate a Converter from one of each, implementing interface:

new Converter(XMLReader, CSVWriter);

(where XMLReader implements IReader & CSVWriter implements IWriter)

But then again, it would be cooler to be able to keep the XML related classes together too.

Can be a simple question with a simple answer, but I was wondering if we could come up with a more elegant solution.

Thanks in advance

asked Feb 19, 2014 at 19:38
3
  • If you have defined classes for XML sources and CSV sources, why not a Converter<IN, OUT> interface which you'd implement for all cases? Commented Feb 19, 2014 at 19:42
  • that d make 4 classes tho, no? could you explain maybe a bit more? Commented Feb 20, 2014 at 9:37
  • 1
    Well, three actually since you can implement an IdentityConverter<T> as a Converter<T, T> ;) You do not really tell much about your reader/writer interfaces though, so it is difficult to come with a "perfect" solution Commented Feb 20, 2014 at 9:40

1 Answer 1

2

Your design is fine. If you want to group your classes together use packages. For example create packages: com.mycompany.xml and com.mycompany.csv. Then put CsvReader and CsvWriter to com.mycompany.csv and XmlReader and XmlWriter to com.mycompany.xml.

answered Feb 19, 2014 at 19:43
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.