Suppose I have something like this:
public abstract class AbstractDataObject
{
public abstract void gettableName();
public void delete()
{
SQLQuery("..." + getTableName()+ "..." );
}
}
public class DataObject extends AbstractDataObject
{
final static String tableName;
public String getTableName()
{
return tableName;
}
}
I want method delete() to query a different table for each subclass of AbstractDataObject. So I override getTableName() just to pass a static constant that’s specific to each subclass. Would this be acceptable or bad practice?
I have done this a lot. Many a times writing a framework, the base class has a
getType()orgetName()or some such abstract method. The derived classes typically override this to return astaticmember’s value`