ExpDev07 / coronavirus-tracker-api

🦠 A simple and fast (< 200ms) API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak. It's written in python using the 🔥 FastAPI framework. Supports multiple sources!
https://coronavirus-tracker-api.herokuapp.com
GNU General Public License v3.0
1.59k stars 323 forks source link

HttpUtils Aggregation Pattern #349

Closed MikePresman closed 3 years ago

MikePresman commented 3 years ago

Files Changes

What has Changed? HttpUtils.py now follows an aggregation pattern where instead of having CLIENT_SESSION act as a global variable it is now part of a boundary where it is only accessible through the root, where the root is an instance of the class 'Session'. This paradigm also applies to LOGGERwhere LOGGER is also part of the boundary.

Because I have applied aggregation here, both LOGGER and CLIENT_SESSION are now encapsulated since their instance does not need to be seen individually but only through the lens of an instance of a Session.

The logic and approach of setup_client_session() and teardown_client_session() remain. What only changes is the encapsulation, and the aggregation of the objects that manage those methods.

Why This change seems appropriate as this change encourages keeping one client_session alive per user and managing that session through an instance of a class rather than passing that session where a lack of encapsulation could cause confusion. As such adding a boundary on the CLIENT_SESSIONand LOGGERmakes perfect sense here through the work of aggregation.

Kilo59 commented 3 years ago

I appreciate the effort.

Their certainly is lot about this application that can and should be improved but I don't see how this particular refactor makes the the project better.