Notes and exercises for learning design patterns
Implement Monostate: many objects, one shared state.
Singleton says:
one object
Monostate says:
many objects, one shared state
In this exercise, Preferences() should create different objects, but all Preferences objects should share the same attributes.
__dict__ to shared storageOpen exercise4.py.
Fill the TODOs so that:
Preferences() creates different objects.Preferences objects share the same __dict__.Preferences(...) calls do not reset the first initialization.first = Preferences(theme="light")
second = Preferences(theme="dark")
assert first is not second
assert first.__dict__ is second.__dict__
assert second.theme == "light"
first.theme = "dark"
assert second.theme == "dark"
python -m pytest exercise4.py