这是场景。
public interface Processor{
public void create();
public void setDocuments();
public abstract void prepareDocuments();
}
public class ProcessorImpl implements Processor{
public void create(){
// Do something
}
public void setDocuments(){
// Do something
}
}
public class ProcessorA implements ProcessorImpl{
// this class will implement only once abstract
// method which is prepareDocuments()
public void prepareDocuments(){
// prepare documents..and also
// set the Documents list which will be checked by create()
// method and then index will be created.
}
}
public class IndexGenerator{
public static void main( String[] args){
ProcessorA a = new ProcessorAImpl();
a.create();
}
}
简要背景......我正在开发一个通用框架来处理所有与 Lucene 索引相关的活动,包括创建索引、从索引中删除文档、更新和添加到索引中。除了创建文档之外,处理索引的所有逻辑都保持不变。每个索引都有不同类型的文档,因此我保留了 prepareDocuments() 方法的抽象,并为每个索引类型实现了它。
现在我想让所有索引生成器类简单地创建其特定索引处理器的实例,如 ProcessorA 并调用 create() 方法。但问题是 create() 方法总是发现文档列表为空/空,尽管 prepareDocuments 通过调用 setDocuments() 方法来设置文档。我知道存在一些设计缺陷,我真的需要向 OO 专家寻求帮助。
谢谢热心