A Singleton guarantees a class has exactly one instance and gives everyone a single point of access to it. Config is the classic case: the whole app should read from and write to the same registry, not scattered copies.
Store the sole instance on the class itself in a private attribute, and hand it out through a classmethod.
Implement instance:
The reset classmethod is already written. It clears _instance so each test starts from a clean slate. The same instance living on the class would otherwise leak state from one test into the next.
class Config:
_instance = None
def __init__(self):
self._data = {}
@classmethod
def instance(cls):
"""Return the one shared Config instance, creating it on first call."""
# TODO: if cls._instance is None create it, then always return cls._instance
pass
@classmethod
def reset(cls):
cls._instance = None
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
A Singleton guarantees a class has exactly one instance and gives everyone a single point of access to it. Config is the classic case: the whole app should read from and write to the same registry, not scattered copies.
Store the sole instance on the class itself in a private attribute, and hand it out through a classmethod.
Implement instance:
The reset classmethod is already written. It clears _instance so each test starts from a clean slate. The same instance living on the class would otherwise leak state from one test into the next.
Press Run Tests or ββ© to check your solution.