G.4.5. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Instance Variables
Let’s reexamine our hierarchy once more, this time using good software engineering practices. Class CommissionEmployee
(Fig. G.10) declares instance variables firstName
, lastName
, socialSecurityNumber
, grossSales
and commissionRate
as private (lines 6–10) and provides public
methods setFirstName
, getFirstName
, setLastName
, getLastName
, setSocialSecurityNumber
, getSocialSecurityNumber
, setGrossSales
, getGrossSales
, setCommissionRate
, getCommissionRate
, earnings
and toString
for manipulating these values. Methods earnings
(lines 93–96) and toString
(lines 99–107) use the class’s get methods to obtain the values of its instance variables. ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.