Thursday, 27 March 2008

Java Interface concept - JDBC way

==== Developer A side ======
class InterfaceTest2 {
public static void main(String[] args) {
A a = new A();
a.methodA();
}
}


==== Developer B side ======
=== Do not change Class name "A" and method "methodA"
=== Except two factors B side can change anything

class A {
void methodA() {
I i = InstanceManager.getInstance();
i.methodB();
}
}

interface I {
public abstract void methodB();
}

class B implements I {
public void methodB() {
System.out.println("methodB in B class");
}
}

class InstanceManager {
public static I getInstance() {
return new B();
}
}

No comments: