Created
August 22, 2011 22:13
-
-
Save iffy/1163772 to your computer and use it in GitHub Desktop.
How to implement
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
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? |
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 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 |
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 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