jeudi 23 juillet 2015

Calling the sub class method from super class isn't best practice?

I am working on a project where we have an abstract class(BaseConverter) with one abstract method(convert()) and few concrete methods. One important concrete method is invokeConverter() which will basically call the convert() method implemented in the subclass.

While our code is being reviewed by other guy, he told that, subclass methods shouldn't be called from superclass and he told it is not best practice. Below is our class structure. Can someone please tell whether this isn't a right way to do?

@Named
public abstract class BaseConverter{ 

     @Inject
     private ConversionDriver conversionDriver;//this class is responsible to return the correct subclass object based on the type

     protected abstract String convert(Object toConvert); 

     public String invokeConverter(ConverterType type, Object toConvert){
       conversionDriver.getConverter(type).convert(toConvert);//getConverter() return the subclass object based on the type
     } 
    ....
    ....
}

Aucun commentaire:

Enregistrer un commentaire