Created
April 18, 2010 14:38
-
-
Save abyx/370251 to your computer and use it in GitHub Desktop.
This file contains 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
# 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