我真的被困在这里了。我正在尝试添加除当前数据库之外的新数据库。我将使用工厂模式来选择正确的数据库控件,如下所示:
private AssetStoresFactory assetStoresFactory;
AssetStore assetStore = assetStoreFactory.getAssetStore(query);
assetStore.search(search);
public AssetStore getAssetStore(String query){
AssetStore assetStore;
if (qualifiesForStoreA(query))
assetStore = new AssetStoreA();
else
assetStore = new AssetStoreB();
return assetStore;
}
AssetStore A
.....
Results search(AssetSearch search) {
AssetSearchOperation o = new AssetSearchOperationA(search);
}
.....
AssetStore B
.....
Results search(AssetSearch search) {
AssetSearchOperation o = new AssetSearchOperationB(search);
}
.....
现在真正的问题在于此。目前执行搜索的方法如下:
_______________________
| BaseSearchOperation |
| ___________________ |
| abstract search() |
-----------------------
ᴧ
|
____________________
| StreamingSupport |
|__________________|
ᴧ
|
______________________
|AssetSearchOperation|
|____________________|
现在有代码可以查询所有上述类中的当前数据库,这需要删除和隔离。我无法理解如何做到这一点。请注意,AssetSearchOperation的匿名实现会覆盖StreamingSupport。 任何帮助表示赞赏!如果您需要更多信息,请询问!
答案 0 :(得分:0)
使用数据库连接实例参数化AssetStore
构造函数,并在工厂方法中传递特定实例。