Magazine
 
Design Pattern

1. Template Design Pattern

These types of design patterns are used as templates. These design patterns are used in such conditions when we need a parent class having one or more methods to be implemented by their child classes. This design pattern
introduces an idea of defining an algorithm in a class and leaving some of the methods to be implemented by their subclasses.

This design pattern is used to develop similar kind of operations template, reusing the common behavior to simplify code, algorithm related improvement, from many generalized to specialized operations.

Lets take an example of loan application, this application may have several steps to complete its processing.

Here we are illustrating several steps to complete:

  • Bank balance history of a client’s check.
  • Credit score of the client’s check taken from three different companies.
  • Other loan information of client’s check.
  • Stock holding value of a client’s check.
  • Future income potential of that client’s check.

In all of the above situations we can use a template method hold the steps of the process together without deliberating the actual implementation of the process’s steps together without considering the real implementation in the subclass.

abstract class CheckVariousdtls {
public abstract void Bankdetails();
public abstract void Creditdetails();
public abstract void Loandetails();
public abstract void Stockdetails();
public abstract void Incomedetails();
public void checkdetails() {
Bankdetails();

 

Creditdetails();
Loandetails();
Stockdetails();
Incomedetails();
}
}
class LoanApplication extends
CheckVariousdtls {
private String name;
public LoanApplication(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void Bankdetails() {
System.out.println(“Checking bank
details...”);
}
public void Creditdetails() {
System.out.println(“Checking credit
details...”);
}
public void Loandetails() {
System.out.println(“Checking other loan
details...”);
}
public void Stockdetails() {
System.out.println(“Checking stock
values details...”);
}
public void Incomedetails() {
System.out.println(“Checking family
income details...”);
}
}
class TestTemplateApplication {
public static void main(String[] args) {
LoanApplication Clientdtls = new
LoanApplication(“Amit”);

 
Mar 2008 | Java Jazz Up |36
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59,

Download PDF