Skip to content

Instantly share code, notes, and snippets.

@avian2
Created June 24, 2015 14:11
Show Gist options
  • Save avian2/c6dd0d758c4d16e1b92a to your computer and use it in GitHub Desktop.
Save avian2/c6dd0d758c4d16e1b92a to your computer and use it in GitHub Desktop.
# pizza.py
class DoughFactory(object):
def get_dough(self):
return 'insecticide treated wheat dough'
class Pizza(DoughFactory):
def order_pizza(self, *toppings):
print('Getting dough')
dough = super().get_dough()
print('Making pie with %s' % dough)
for topping in toppings:
print('Adding: %s' % topping)
if __name__ == '__main__':
Pizza().order_pizza('Pepperoni', 'Bell Pepper')
# better_pizza.py
from pizza import Pizza, DoughFactory
class OrganicDoughFactory(DoughFactory):
def get_dough(self):
return 'pure untreated wheat dough'
class OrganicPizza(Pizza, OrganicDoughFactory):
pass
if __name__ == '__main__':
OrganicPizza().order_pizza('Sausage', 'Mushroom')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment