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

add creational design pattern: singleton #132

Closed akhtar-u closed 2 years ago

akhtar-u commented 3 years ago

Implemented the singleton design pattern to the covid19.py class. As we can use the same instance of the covid19 object to perform all data lookup it makes sense to restrict this class to only have 1 instance as the global access point. This pattern was applied by creating a new static method to provide access to the object and the constructor was modified to check if another instance exists and if it does to raise an exception. This way only one instance of the object is in memory at any time.