mercredi 15 mai 2019

How to design an API where data source can be File or API or a third party system using design patterns such as Factory and Adapter?

I'm working on a Spring Integration (SI) application and having two different data source - File and an API from where I get the data to process. Based on the input of data source type, either we read the file and process it or we call an API and get the data to process it further. Currently both SI flows are different. However, based on client requirement, now we need to merge those two flows into a single one and hence we need to implement certain design patterns to make it more generic and extensible so that it becomes possible if in future some other data source comes in, we need to do minimum code changes.

The design patterns we need to implement are - Factory Design Pattern and Adapter Design Pattern.

  1. Factory the implementation for the data source using the some configuration.

  2. Read content from configured data source using adapter interface, process should be agnostic of type (i.e. File or API)

How should I implement these two design patterns based on above points ?

For Factory Pattern, I think it is easy. A factory class can be implemented which based on a data source type can return a concrete class FileDataSource or ApiDataSource. However, I am not sure what would be inside those concrete classes. Also, Adapter pattern I am not sure of. I have read it theoretically but haven't used it practically.

Any help will be appreciated. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire