Please send questions to
st10@humboldt.edu .
'''
lect09_7.py - example of a Python subclass
Superclass Employee and Subclass Chef
modified from "Learning Python", Lutz and Ascher, O'Reilly
p. 347, I think, but example is referred to in Chapters 19-23
adapted by: Sharon M. Tuttle
last modified: 10-24-06
'''
from lect09_6 import Employee
class Chef(Employee): # Chef is now a subclass of Employee;
"""
Chef class is a subclass of Employee who handles cooking
"""
def __init__(self, lastname, maxMich=0): # overloading
"""
Chef constructor: Chef's salaries are initially 50000,
but their highest Michelin rating needs to be noted
(assumed to be 0 if not given)
"""
Employee.__init__(self, lastname, 50000)
self.maxMich = maxMich
def work(self): # overloading
"""
Prints to the screen a Chef's job description
"""
print self.lastname, "makes food"
def setMaxMich(self, newRating):
"""
update this Chef's maximum Michelin rating;
(will NOT decrease it; is ignored if proposed
new rating is lower)
"""
self.maxMich = max(self.maxMich, newRating)
def __repr__(self):
"""
return a string representation of a Chef
"""
partial = Employee.__repr__(self)
return partial[0:-1] + " maxMich=%d>" % self.maxMich