Java Reference
In-Depth Information
checkCreditHistory ();
checkIncomeHistory ();
reportFindings ();
}
protected
protected abstract
abstract void
void checkIdentity () throws
throws ApplicationDenied ;
protected
protected abstract
abstract void
void checkIncomeHistory () throws
throws ApplicationDenied ;
protected
protected abstract
abstract void
void checkCreditHistory () throws
throws ApplicationDenied ;
private
private void
void reportFindings () {
CompanyLoanApplication implements checkIdentity by looking up information in a
company registration database, such as Companies House. checkIncomeHistory would in-
volve assessing existing profit and loss statements and balance sheets for the firm. check-
CreditHistory would look into existing bad and outstanding debts.
PersonalLoanApplication implements checkIdentity by analyzing the paper statements
that the client has been required to provide in order to check that the client's address exists.
checkIncomeHistory involves assessing pay slips and checking whether the person is still
employed. checkCreditHistory delegates to an external credit payment provider.
EmployeeLoanApplication is just PersonalLoanApplication with no employment his-
tory checking. Conveniently, our bank already checks all its employees' income histories
when hiring them ( Example 8-22 ).
Example 8-22. A special case of an an employee applying for a loan
public
public class
class EmployeeLoanApplication
EmployeeLoanApplication extends
extends PersonalLoanApplication {
@Override
protected
protected void
void checkIncomeHistory () {
// They work for us!
}
}
With lambda expressions and method references, we can think about the template method
pattern in a different light and also implement it differently. What the template method pat-
tern is really trying to do is compose a sequence of method calls in a certain order. If we rep-
resent the functions as functional interfaces and then use lambda expressions or method ref-
erences to implement those interfaces, we can gain a huge amount of flexibility over using
Search WWH ::




Custom Search