Created
March 14, 2013 13:12
-
-
Save n9986/5161185 to your computer and use it in GitHub Desktop.
Python simple factory style
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
class MultipleChoice(): | |
name = "multiplechoice" | |
class QuestionBuilderFactory(): | |
classes = {} | |
def register(self, cls): | |
# print getattr(cls, name) | |
print cls.name | |
self.classes[cls.name] = cls | |
def create_class(self, t): | |
return self.classes[t]() | |
qb = QuestionBuilderFactory() | |
qb.register(MultipleChoice) | |
print qb.create_class("multiplechoice") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment