Weekly Recap 20181112–1118
It’s a tiring week due to kid’s flu. Be healthy!
[Programming] Different design learnt when integrating similar services with different APIs
I was working on an internal system which integrates several advertisement network reporting APIs. To get the report from them, we need to pass the start date, the end date and the dimensions for the metrics. At the beginning with one provider, it’s very straightforward to have our program looks like the sequence diagram below. A server wrapper which provides the interface with those necessary arguments.
And it’s pretty easy to get to the next diagram when we add the second, the third and so on.
It looks fine, but what if some of the wrappers have more necessary arguments for query, our main program will know too much about those wrappers. Therefore, we introduced QueryContext class which collects all the arguments for the work and the context instance would be passed into each wrapper. Wrappers communicate with the context for those necessary information they need to accomplish the job. The updated diagram is below.
So what benefits we have from the last design?
- Decouple the main program and the wrappers so that it’s easier to test our main program.
- Wrappers hold their own knowledge about how to prepare the request to fulfill the request from main program.
[Reading] Organize knowledge
There are always rooms for improving how I organize my readings and findings. This posts shares several services to organize our knowledge. I use some of the services but I don’t use them in this way. Some other services are new to me. It would be interesting to try.