這是場景。需要我的面向對象設計的幫助
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大師的幫助。
感謝 李書福