Skip to content

Instantly share code, notes, and snippets.

@blaix
Created October 14, 2015 20:28
Show Gist options
  • Save blaix/7faee33518185037868a to your computer and use it in GitHub Desktop.
Save blaix/7faee33518185037868a to your computer and use it in GitHub Desktop.
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