|
Design Pattern |
System.out.println(“\nChecking “ +
Clientdtls.getName()+ “ (client) loan details.
“);
Clientdtls.checkdetails();
LoanApplication Clientloandtls = new
LoanApplication(“Aqueel”);
System.out.println(“\nChecking “ +
Clientloandtls.getName()+ “ (client) loan
details. “);
Clientloandtls.checkdetails();
}
}
Best example of template design pattern is
method overloading and method overriding. For
example,
The example illustrated below has an add()
method that is a template method. This add()
method may take any primitive type numerical
value and we can type cast the result according
to our requirement.
abstract class AddNumbers {
public abstract double addnumbers(double
d1, double d2);
}
class AddAnyTypeOfNumber extends
AddNumbers{
public double addnumbers(double d1,
double d2) {
return d1 + d2;
}
}
|
|
class TestApplication {
public static void main(String[] args) {
byte b1 = 6, b2 = 2;
short s1 = 4, s2 = 6;
int i1 = 1, i2 = 8;
long l1 = 5, l2 = 9;
float f1 = 14.7f, f2 = 37.9f;
double d1 = 12.7, d2 = 11.2;
AddAnyTypeOfNumber
addanytypeNumber = new
AddAnyTypeOfNumber();
System.out.println(addanytype
Number.addnumbers(d1,d2));
System.out.println((float)addanytype
Number.addnumbers(f1,f2));
System.out.println((long)addanytype
Number.addnumbers(l1,l2));
System.out.println((int)addanytype
Number.addnumbers(i1,i2));
System.out.println((short)addanytype
Number.addnumbers(s1,s2));
System.out.println((byte)addanytype
Number.addnumbers(b1,b2));
}
}
|
|
Mar 2008 | Java Jazz Up | 37 |
|
|
|
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 |
|
|
|
|
|
|
|