Switching from abstract class to interface
- by nischayn22
I have an abstract class which has all abstract methods except one which constructs objects of the subclasses. Now my mentor asked me to move this abstract class to an interface.
Having an interface is no problem except with the method used to construct subclass objects. Where should this method go now?
Also, I read somewhere that interfaces are more efficient than abstract classes. Is this true?
Here's an example of my classes
abstract class Animal {
//many abstract methods
getAnimalobject(some parameter) {
return //appropriate subclass
}
}
class Dog extends Animal {}
class Elephant extends Animal {}