Skip to content

Instantly share code, notes, and snippets.

@iffy
Created August 22, 2011 22:13
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 iffy/1163772 to your computer and use it in GitHub Desktop.
Save iffy/1163772 to your computer and use it in GitHub Desktop.
How to implement
Customer's can purchase things, and employees can be paid a commission for assisting the customer in their purchase. What methods would you create to do this?
class Employee:
name = None
def getCommission(self, product):
if product == 'apple':
return 1.0
else:
return 0.5
class Customer:
name = None
def purchase(self, product, amount):
p = Purchase()
p.product = product
p.amount = amount
p.customer = self
return p
def employee_assisted_purchase(self, employee, *a, **kw):
p = self.purchase(*a, **kw)
c = Commission()
c.employee = employee
c.purchase = p
c.amount = employee.getCommission(p.product)
return p
class Purchase:
name = None
customer = None
amount = None
class Commission:
purchase = None
employee = None
amount = None
class Employee:
name = None
def getCommission(self, product):
if product == 'apple':
return 1.0
else:
return 0.5
def customer_purchase(self, customer, *a, **kw):
p = customer.purchase(*a, **kw)
c = Commission()
c.employee = self
c.purchase = p
c.amount = self.getCommission(p.product)
return p
class Customer:
name = None
def purchase(self, product, amount):
p = Purchase()
p.product = product
p.amount = amount
p.customer = self
return p
class Purchase:
name = None
customer = None
amount = None
class Commission:
purchase = None
employee = None
amount = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment