【发布时间】:2019-10-11 19:03:45
【问题描述】:
我有一个下面的方法,我使用这条线ProcBOF.getInstance().find 来获取一些数据。
private static Map<Long, Long> getAll(Map<Long, Event> holder) throws FinderException {
Map<Long, Long> map = new HashMap<>();
if (holder.isEmpty()) {
return map;
}
Set<Long> items = holder.keySet();
long[] itemIds = Longs.toArray(items);
List<TeraBo> teraBos = TBOF.getInstance().findItemIdsIn(itemIds);
for (TeraBo tBo : teraBos) {
ProcessBo bo = ProcBOF.getInstance().find(tBo, holder.get(tBo.getItem().getId()).getDataId(), ReadSet.FULL, null);
bo.getVar();
map.put(tBo.getItem().getId(), bo.getVar());
}
return map;
}
现在我想模拟ProcBOF 类的find 方法,以便它可以返回一些虚拟的ProcessBo 对象,我们可以从中调用getVar() 方法,但问题是ProcBOF 是一个抽象类,并且find 是一个抽象方法,所以我无法理解如何模拟这个抽象类的抽象方法。
public interface ProcessBo extends BOI {
//...
}
public abstract class ProcBOF extends BaseBof {
//...
public abstract ProcessBo find(TeraBo saleBo, long dataId, ReadSet readSet, Filter filter) throws FinderException;
}
【问题讨论】:
-
重构您的代码以消除隐藏的依赖关系,这样会更容易使用和测试。