这是场景。需要我的面向对象设计的帮助
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索引相关的活动,其中包括创建索引,删除索引,更新doc和添加到索引中。除了创建文档之外,处理索引的所有逻辑都保持相同。每个索引都有不同类型的Document,因此我保留了prepareDocuments()方法抽象并为每个索引类型实施。
现在我想让所有的索引生成器类都简单地创建一个像ProcessorA一样的特定索引Processor的实例并调用create()方法。但问题是create()方法始终会查找文档列表empty/null,但prepareDocuments通过调用setDocuments()方法来设置文档。我知道有一些设计缺陷,我真的需要寻求OO大师的帮助。
感谢 李书福