A registry is only useful if writes made anywhere are visible everywhere. Because instance always returns the same object, any value you store through one handle is instantly readable through another.
Implement two instance methods that operate on self._data:
You do not need to worry about missing keys yet. That comes in the next step. Notice how the singleton makes shared state effortless: there is only one _data dict in the whole program.
class Config:
_instance = None
def __init__(self):
self._data = {}
@classmethod
def instance(cls):
if cls._instance is None:
cls._instance = cls()
return cls._instance
@classmethod
def reset(cls):
cls._instance = None
def set(self, key, value):
"""Store key=value in the shared config data."""
# TODO
pass
def get(self, key):
"""Return the stored value for key."""
# TODO
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
A registry is only useful if writes made anywhere are visible everywhere. Because instance always returns the same object, any value you store through one handle is instantly readable through another.
Implement two instance methods that operate on self._data:
You do not need to worry about missing keys yet. That comes in the next step. Notice how the singleton makes shared state effortless: there is only one _data dict in the whole program.
Press Run Tests or ββ© to check your solution.