Skip to content

Instantly share code, notes, and snippets.

@xarg
Created November 23, 2011 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xarg/1388877 to your computer and use it in GitHub Desktop.
Save xarg/1388877 to your computer and use it in GitHub Desktop.
Apples and Oranges with a wrapper
class Apple:
worm = "~~~"
class Orange:
def slices(self):
return [1, 2, 3]
def get_slices(basket):
"""For each item in the basket get it's slices"""
slices = []
for item in basket:
slices.append(item.slices())
return slices
class AppleWrapper:
""" This class takes an apple and provides aditional functionality for it"""
def __init__(self, apple):
self.apple = apple
def slices(self):
self.apple.worm = None #remove the worm
return [1, 2, 3, 4]
if __name__ == '__main__':
basket = []
basket.append(Orange())
basket.append(AppleWrapper(Apple()))
print get_slices(basket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment