如果我的 childClass 方法 getInfoFromDB() 和 saveToDB() 需要执行不同的逻辑,我可以知道如何创建 childClass 吗?
public abstract class BaseClass {
public abstract Object doTransaction();
public Object executeTrans() {
//do something
tx.begin();
this.doTransaction();
tx.commit();
}
}
public childClass extends BaseClass{
@Override
public Object doTransaction(){
//overide to get something from database so can only be used for getInfoFromDB() and not for saveToDB()
return something;
}
public List<String> getInfoFromDB(){
super.executeTrans();
}
public void saveToDB(){
super.executeTrans() ;
}
}