[Tutor] Why None?

Sean Perry shaleh at speakeasy.net
Tue Feb 7 21:48:39 CET 2006


Hey Chris, check out this version.

class Food:
     def __init__(self, name):
         self.name = name

class Customer:
     def __init__(self,name):
         self.name = name
         self.food = None # 0 is for numbers
     def placeOrder(self, foodName, employee):
         print "%s: Hi %s!" % (self.name, employee.name)
         print "%s: I want %s please! " % (self.name, foodName)
         self.food = employee.takeOrder(foodName)
     def foodOrdered(self):
         return self.food.name

class Employee:
     def __init__(self, name):
         self.name = name
     def takeOrder(self, foodName):
         print "%s: %s coming up!" % (self.name, foodName)
         return Food(foodName)

class MealOrder:
     def __init__(self, employee, customer):
         self.employee = employee
         self.customer = customer
     def set(self, foodName):
         self.customer.placeOrder(foodName, self.employee)
     def result(self):
         print "%s has %s" % (self.customer.name,
                              self.customer.foodOrdered())

if __name__ == '__main__':
     order = MealOrder(Employee('Dave'), Customer('Chris'))
     order.set('spam')
     order.result()


More information about the Tutor mailing list