I was looking at Java code, and I saw that the objects were allocated using some interface, and this interface contains some methods of selecting objects using the new operator. I cannot understand why they used the interface instead of directly selecting objects using the new operator. eg:
Animal animal = new Animal();
OR
Animal animal = interface.allocateAnimal()
here interface is an interface that has a allocateAnimal method that does nothing new Animal() .
So, ultimately, we do the same thing, but in a different way, so what is typing here?
EDIT 1: Actually, the interface is implemented somewhere else. Thus, the interface does not contain implementation code, it just contains methods.
source share