![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
So far, you have learned how you can define a Vegetable
class. Now
suppose that you want to add three more specific classes for dairy
products, meats, and grains.
You could, of course, repeat what you have defined for the Vegetable
class, including fCalories
, cCalories
, and pCalories
instance variables, along with corresponding setters and getters.
However, maintaining multiple copies of instance variables and methods makes software development and maintenance difficult as you try to correct bugs, to add features, to improve performance, and to change behavior. Adding multiple programmers and multiple years to the mix turns mere difficulty into certain failure.