Created
September 5, 2013 19:56
-
-
Save mike-burns/6455313 to your computer and use it in GitHub Desktop.
Example builder pattern in Python
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
class ThingyMaker(object): | |
def __init__(self): | |
self.thingy = None | |
self.widget = None | |
def with_thingy(self, thingy): | |
self.thingy = thingy | |
return self | |
def with_widget(self, widget): | |
self.widget = widget | |
return self | |
def make_thingy(self): | |
return Thingy(self.thingy, self.widget) | |
class Thingy(object): | |
def __init__(self, thingy, widget): | |
self.thingy = None | |
self.widget = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment