-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLoosleyCoupled.java
More file actions
100 lines (89 loc) · 2.39 KB
/
LoosleyCoupled.java
File metadata and controls
100 lines (89 loc) · 2.39 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.ResourceBundle;
interface IProducer{
void show();
void input();
}
class EnhanceProducer implements IProducer{
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("Enhance Producer Show");
}
@Override
public void input() {
// TODO Auto-generated method stub
System.out.println("Enhance Producer input");
}
}
class Producer implements IProducer{
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("Producer Show");
}
@Override
public void input() {
// TODO Auto-generated method stub
System.out.println("Producer Input");
}
public void notExpose1(){
System.err.println("Not Expose 1");
}
public void notExpose2(){
System.err.println("Not Expose 2");
}
public void notExpose3(){
System.err.println("Not Expose 3");
}
}
interface Factory{
public static final ResourceBundle rb = ResourceBundle.getBundle("config");
public static IProducer getInstance(){
// First read the property file
Object object = null;
String className = rb.getString("classname");
try{
object = Class.forName(className).getDeclaredConstructor().newInstance();
}
catch(Exception e){
System.out.println("Class Not Found "+e);
}
return (IProducer)object;
// if(className.equals("EnhanceProducer")){
// return new EnhanceProducer();
// }
// return new Producer();
//return new EnhanceProducer();
}
}
class ConsumerA{
void call(){
IProducer p = Factory.getInstance();
//IProducer p = new Producer(); // Upcasting
p.show();
p.input();
// p.notExpose1();
// p.notExpose2();
// p.notExpose3();
}
}
class ConsumerB{
void call(){
IProducer p = Factory.getInstance();
//IProducer p = new Producer();
p.show();
p.input();
// p.notExpose1();
// p.notExpose2();
// p.notExpose3();
}
}
public class LoosleyCoupled {
public static void main(String[] args) {
ConsumerA c = new ConsumerA();
c.call();
System.out.println("************************");
ConsumerB c2 = new ConsumerB();
c2.call();
}
}