Your design is a bit unorthodox, Animal::getAnimalobject() is inherited to Dog and Elephant unnecessarily. What you need to do is:
- Move all the abstract functions in the interface,
- Have your
DogandAnimalElephantclasses implement theanAnimalinterface, - Continue creating them via a factory method, as you currently do.
...and you'll probably want to rename Animal (the class) to AnimalFactory.