Last active
November 11, 2015 01:49
-
-
Save goodwillcoding/3582b811275ed6a12cd2 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
class Engine(object): | |
def __init__(self, size): | |
self.size = size | |
def turn_on(self): | |
print "vrooom" | |
class BiggerEngine(object): | |
def __init__(self, size): | |
self.size = size | |
def turn_on(self): | |
print "VRROOOOOMMMM" | |
class CarFactory(object): | |
def __new__(self, engine_class): | |
class MyCar(object): | |
def __init__(self, engine_size): | |
self.engine = engine_class(size=engine_size) | |
return MyCar | |
car_class = CarFactory(engine_class=Engine) | |
print car_class | |
car = car_class(engine_size="v4") | |
print car | |
car.engine.turn_on() | |
car_class = CarFactory(engine_class=BiggerEngine) | |
print car_class | |
car = car_class(engine_size="super") | |
print car | |
car.engine.turn_on() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment