Created
October 14, 2015 20:28
-
-
Save blaix/7faee33518185037868a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def write(msg): | |
print msg | |
class Plugins(object): | |
plugins = { | |
'writer': write, | |
} | |
@classmethod | |
def register(cls, name, plugin): | |
cls.plugins[name] = plugin | |
@classmethod | |
def get(cls, name): | |
return cls.plugins[name] | |
def double_write(msg): | |
print msg | |
print msg | |
Plugins.register('writer', double_write) | |
class Messenger(object): | |
def send(self, msg): | |
writer = Plugins.get('writer') | |
writer.write(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment