mardi 18 juillet 2017

Design pattern for multiple versions of class/algorithm

I am storing and parsing xml files, those files evolve over time so when stored I also store the version of the format.

When I load an xml I get the version of the file and based on this version I use a specific java class to process it. The xml format is changing every few weeks so a new class is being created and added to the list of classes. I can load any version of an xml any time (e.g. today I can load xml files created two years ago with version v02 while currently is at version v26)

Is there a design pattern for this kind of problem ? Is there a design pattern using dependency injection for this kind of problem ?

Currently I have a java interface defining a DocumentParser and I have several DocumentParsers each in different package (e.g. com.parsers.v1.DocumentParserImpl) and I have a provider class DocumentParserProvider to supply the proper parser using the version (e.g. public DocumentParser get(String version); ). The interface api never changes, that is we always ask the same thing from our interface.

Is there a better way to do it or is there a name for this problem?

Aucun commentaire:

Enregistrer un commentaire