Switching from abstract class to interface

Posted by nischayn22 on Programmers See other posts from Programmers or by nischayn22
Published on 2012-06-26T13:46:27Z Indexed on 2012/06/26 15:24 UTC
Read the original article Hit count: 250

Filed under:
|

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 {}

© Programmers or respective owner

Related posts about interfaces

Related posts about abstract-class