This Looks Like a Job For


#1
class PartTimeEmployee(Employee):
  def calculate_wage(self, hours):
    self.hours = hours
    return hours * 12.00

  def full_time_wage(self,hours):
    return super(PartTimeEmployee, self).calculate_wage(hours)

Can someone explain why hours is needed inside of the super(PartTimeEmployee, self).calculate_wage(hours) line?

I somewhat understand that calculate_wage needs two args, self and hours – the super call tells calculate_wage which class to refer to (parent class), so the hours inside parenthesis is simply needed to complete the method?


#2

Besides being needed in order to match with the method’s parameters, the number of hours is needed to compute the wages. Without information regarding the duration of time that the PartTimeEmployee or Employee worked, we cannot compute how much to pay.


#3

I was more or less confused as to why it wouldn’t be inherited from the parent class


#4

Methods and class variables are inherited from the parent class. However, instance variables need to assigned values at the time that an instance of a class is created or later on. In the current case, we need to communicate how many hours a PartTimeEmployee or Employee worked, and the best means of doing that is by providing an argument when we call a method. Depending on how we design our classes, that method could be one that we defined in the child class or one that is inherited from the parent class. Either way, we must call some appropriate method and supply whatever arguments are needed to convey the relevant information.


#5