0
Not a bug

getAnnualCost should be getTotalAnnualCost

Abelardo León González 7 years ago updated by Marina Pavlova 7 years ago 1

Hi SourceMaking staff,

At this article, the right picture might contain a mistake:


The 'Department' class shouldn't have the ''getAnnualCost' but 'getTotalAnnualCost' 
The "Employee" class should have only the 'getID' method.


Kinds regards

Answer

Answer
Not a bug

Hi, Abelardo!


The reason why they both get the getAnnualCost method is because you'd want to unify their interfaces.


To achieve that, you'll need to rename the Department's method, but leave the Employe's method intact. If both of these methods had similar implementation, you could pull them to the base class and get rid of the method in subclasses altogether (like with getName).


But here we just assume that that wasn't possible and there are still some need for the overriding. Again, it can play out in different ways in real life.


Hope this makes sense.

Answer
Not a bug

Hi, Abelardo!


The reason why they both get the getAnnualCost method is because you'd want to unify their interfaces.


To achieve that, you'll need to rename the Department's method, but leave the Employe's method intact. If both of these methods had similar implementation, you could pull them to the base class and get rid of the method in subclasses altogether (like with getName).


But here we just assume that that wasn't possible and there are still some need for the overriding. Again, it can play out in different ways in real life.


Hope this makes sense.