Can someone explain to me what the meaning of creating a variable of an Interface class is?
Specifically, what does the following code mean:
InterfaceA x = (InterfaceA) factory.createFactoryObject(zz.CONST);
I have always thought that an interface (in Java) is simply a collection of method declarations whose functionality is defined by classes implementing an interface. For example if I have an interface:
public interface IMoveBehavior(){
public void move_Along_X();
public void move_Along_Y();
public void move_Along_Z();
}
then the class would use this interface as:
public class ABC() implements IMoveBehavior{
public void move_Along_X(){
//do whatever
}
public void move_Along_Y(){
//do whatever
}
public void move_Along_Z(){
//do whatever
}
}
So, coming back to
InterfaceA x = (InterfaceA) factory.createFactoryObject(zz.CONST);
I really do not understand what exactly this means conceptually. Could someone explain or point me to a resource where I can educate myself?
Thanks!!