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
1 Answer 1
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.
Comments
Explore related questions
See similar questions with these tags.
Converter<IN, OUT>interface which you'd implement for all cases?IdentityConverter<T>as aConverter<T, T>;) You do not really tell much about your reader/writer interfaces though, so it is difficult to come with a "perfect" solution