mercredi 26 juillet 2017

most suitable design pattern to choose parser based on input file

I have my input file in all XML/JSON/CSV/EXCEL formats.

I have written separate parsers for all. but I wanna choose my parse at run time.

which design pattern will be most suitable ?

I have implemented such as

if(file.endsWith(".csv"))
return CSVParser();
if(file.endsWith(".json"))
return JSONParser();
if(file.endsWith(".xml"))
return XMLParser();
else
return EXCELParser();

suggestion/guidelines please .

Aucun commentaire:

Enregistrer un commentaire