So I am doing a project and I have 2 interfaces.
Let's call them:
public interface A{
}
public interface B{
}
And I have 4 different classes that implement these interfaces, because I need to either run them locally or over the network:
public class Class1 implements A{
// logical implementation of A
}
public class Class2 implements B{
// logical implementation of B
}
public class Class3 implements A{
// proxy implementation of A
}
public class Class4 implements B{
// proxy implementation of B
}
Class1 and Class3 implement the logic of the interfaces while Class2 and Class4 implement the Proxies of these interfaces. I am now trying to test these classes and I have the following code:
private static Class1 object1;
private static Class2 object2;
if (localTest) {
object1 = new Class1();
object2 = new Class2();
} else {
object1 = new Class3();
object2 = new Class4();
}
According to the code above I get the error that the class of object1 is incompatible with Class3 and so is the class of object2 with Class4.
Since Class1 and Class3 implement the same interface and Class2 and Class4 implement the same interface, why do i get the error?
I am sorry if i cannot get in any more specifics.
thanks