Skip to content

Instantly share code, notes, and snippets.

@goodwillcoding
Last active November 11, 2015 01:49
Show Gist options
  • Save goodwillcoding/3582b811275ed6a12cd2 to your computer and use it in GitHub Desktop.
Save goodwillcoding/3582b811275ed6a12cd2 to your computer and use it in GitHub Desktop.
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