I have simple task to read the information from different files xml, rdf, txt with different structure and put it in some POJO custom object(MyObject). SO I am wondering which design pattern to use to make my code with better design.
I think on the problem and I think I need Factory Patter and the Iterator Pattern. On the factory to pass the file:
ReaderFactory factory = new ReaderFactory("input.rdf");
//ReaderFactory factory = new ReaderFactory("input.xml");
Iterator<MyObject> iter = factory.getIterator();
So the factory base on the file extension to choose which implemnetation of the iterator to return - these which reads rdf,xml or txt. Then with this iterator I easily can process the objects. Add add new files extensions reading in the future.
Aucun commentaire:
Enregistrer un commentaire