Java Reference
In-Depth Information
public double getWeeklyPay()
{
return weeklyPay;
}
public void computePay(int hoursWorked)
{
weeklyPay = hoursWorked * 6.50;
System.out.println(“Weekly pay for “ + name
+ “ is $” + weeklyPay);
}
public void mailCheck()
{
System.out.println(“Mailing check to “ + name
+ “ at “ + address);
}
}
Imagine that we have two departments in our company—a Payroll Depart-
ment for handling the weekly payroll duties, and a Human Resources Depart-
ment for managing general information about employees. The Payroll
Department does not need to access or change the personal information about
an employee. The Human Resources Department needs access to an
employee's information, but should not be accessing any paycheck details.
The methods pertinent to the Payroll Department can be exposed in one
interface, and the methods pertinent to the Human Resources Department can
be exposed in another interface.
For example, the following interface named Payable exposes three methods
from the Employee class.
public interface Payable
{
public void computePay(int hoursWorked);
public void mailCheck();
public double getWeeklyPay();
}
The following interface named EmployeeInfo exposes four methods from
the Employee class.
public interface EmployeeInfo
{
public String getName();
public void setName(String n);
public String getAddress();
public void setAddress(String a);
}
Search WWH ::




Custom Search