Skip to content

Instantly share code, notes, and snippets.

@abyx
Created April 18, 2010 14:38
Show Gist options
  • Save abyx/370251 to your computer and use it in GitHub Desktop.
Save abyx/370251 to your computer and use it in GitHub Desktop.
# Happily turned this ugly thing:
class Foo(object):
pass
class Bar(object):
pass
class User(object):
def collect(objects):
foos = [x for x in objects if isinstance(x, Foo)]
bars = [x for x in objects if x not in foos]
# To this!
class Foo(object):
def register_yourself(self, registrator):
registrator.register_foo(self)
class Bar(object):
def register_yourself(self, registrator):
registrator.register_bar(self)
class User(object):
def collect(objects):
self.registrator.register(objects)
foos = self.registrator.foos()
bars = self.registrator.bars()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment