samedi 25 février 2017

Using Strategy Pattern for supporting uploading file from multiple sources

I am working on a web app project which requires me to refactor file uploading feature. Our file uploading feature supports multiple sources of uploading file, such git repo, nexus URL, zip files and we also want to support more such as perforce in the future. In the current implementation, the application has multiple endpoints to handle different methods such as getNexusFile(), getGitFile(), getZipFile(); under each method, the file is retrieved from specified source.

My idea is to use merge all these methods into one method called getUploadFile() by using Strategy Pattern. As in the Strategy pattern, algorithms could be selected at runtime, so files uploaded from different sources could be treated indifferently after I specify the right strategy. For every source, I’ll create a strategy for it.

My question is: is that a good practice of design pattern? Is there any better approach to model this question?

Thanks

Aucun commentaire:

Enregistrer un commentaire