G.12.1. Developing a Payable Hierarchy
To build an application that can determine payments for employees and invoices alike, we first create interface Payable
, which contains method getPaymentAmount
that returns a double
amount that must be paid for an object of any class that implements the interface. Method getPaymentAmount
is a general-purpose version of method earnings
of the Employee
hierarchy—method earnings
calculates a payment amount specifically for an Employee
, while getPaymentAmount
can be applied to a broad range of unrelated objects. After declaring interface Payable
, we introduce class Invoice
, which implements
interface Payable
. We then modify class Employee
such that it also implements interface Payable
. Finally, we update Employee ...
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.