2

After I used "inFusion Hydrogen" to analyze my project, it's pretty easy to figure out myQuestionFun() is causing feature-envy.

public abstract class Father{
    protected DataModel dataModel;
    public abstract void myQuestionFun();
}
public class Child extends Father{

    public DataModel<TableInfo> tableList = new DataModel<TableInfo>;
    public DataModel<TableInfo> getTableList(){
        return this.tableList;
    }

    @Override
    public DataModel<Report> getDataModel(){
        return this.dataModel;
    }

    @Override
    public void myQuestionFun(){
        List<TableInfo> tabList = new ArrayList<TableInfo>();
        for (int i=0; dataModel.getDataList().size(); i++) {
            Report rep = (Report)dataModel.getDataList.get(i);
            TableInfo tabInfo = new TableInfo();
            tabInfo.setId(rep.getId());
            tabInfo.setName(rep.getName());
            tabList.add(tabInfo);
        }
        tableList.setPage(dataModel.getPage());
        tableList.setSorter(dataModel.getSorter());
   }
}

The question is, what's the best way to fix it? Because myQuestionFun() is a function of the abstract method of the parent class, I can't move it.

4

2 に答える 2

0

dataModelフィールド フォームを削除Fatherし、インターフェイスに変更します。

于 2016-07-19T13:20:08.900 に答える