Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for aggregation/gathering from different sources

What design pattern should you utilize when you gather information from different sources into a general model of your own?

An example could be polling videos from different video-streaming services into a generalized model. In other words, each video-streaming service will have their own representation of a Video object with a different set of properties. So you want to gather these different constructs and aggregate them into a generalized Video object.

Is there some well known design pattern to make us of? What I have done is to have a factory for each API which have the responsibility to create the general model out of the api-model. Is this a good approach?

like image 751
Bj Blazkowicz Avatar asked May 04 '26 14:05

Bj Blazkowicz


2 Answers

your problem statement does not seem like fitting into scope of a single design pattern. As you have mentioned you are getting data from different sources and want to group them in that case a Composite Pattern can be a good choice.

As you need to communicate to different sources for input, it would be good to have that part completely asynchronous so that you don't block your main program for that.

You might also want to use an abstract factor as you seem to have need to initialize multiple instances of different source system interaction APIs.

And to keep your other systems/services independent of each other, dependency injection would be good to have.

Hope this helps.

like image 198
JustCode Avatar answered May 06 '26 05:05

JustCode


If your general model will be used further in your application and doesn't care where the information is coming from then an abstract Factory pattern with may be a common interface. If your application needs to know where the data is coming from or your API have some common functionalities and some specifics of their own then combine factory and repository patterns.

like image 45
Azhar Khorasany Avatar answered May 06 '26 04:05

Azhar Khorasany



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!