Skip to content

Instantly share code, notes, and snippets.

@shrimo
Last active September 1, 2022 00:16
Show Gist options
  • Save shrimo/a4ca97c79b391c7495dc4fb975ddd472 to your computer and use it in GitHub Desktop.
Save shrimo/a4ca97c79b391c7495dc4fb975ddd472 to your computer and use it in GitHub Desktop.
Memorizer
class DataBuffer:
""" Observer pattern """
def __init__(self):
self.memory = None
def remember(self, memory):
self.memory = memory
def recall(self):
out = self.memory
self.memory = None
return out
class Work:
def __init__(self, mem):
self.mem = mem
def test(self):
self.mem.remember('from Work')
class WorkX:
def __init__(self, mem):
self.mem = mem
def test(self):
print(self.mem.recall())
MX = DataBuffer()
wk = Work(MX)
wkx = WorkX(MX)
wk.test()
wkx.test()
wkx.test()
wk.test()
wkx.test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment