Kamaropoulos / COVID19Py

A tiny Python package for easy access to up-to-date Coronavirus (COVID-19, SARS-CoV-2) cases data.
https://pypi.org/project/COVID19Py/
GNU General Public License v3.0
84 stars 57 forks source link

Singleton Implementation #115

Closed calto05 closed 2 years ago

calto05 commented 3 years ago

I have implemented the singleton creational pattern within the COVID19 class. Once an instance of COVID19 is created it is stored in the class field __singleInstance. If the user tries to make another instance of COVID19 an exception is thrown. The creation of the initial instance can be done through either the constructor or the getInstance method. If the user attempts to make another instance of COVID19 through the getInstance method then no error is thrown and the original instance is passed to the user. The goal of this modification is to avoid potential bugs that could arise when multiple instances of the COVID19 class are created, that could be making multiple requests to the same covid19 backend concurrently within the same user program. The class should behave as it did before bar this change which I tested for during development. Just to note a future pull request which I should be making soon would conflict with this one as it involves extending the API beyond its current scope. I will leave a note there, but please do not merge both as it will not work.