🦠 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!
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.
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.
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 toLOGGER
whereLOGGER
is also part of the boundary.Because I have applied aggregation here, both
LOGGER
andCLIENT_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()
andteardown_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_SESSION
andLOGGER
makes perfect sense here through the work of aggregation.