我有一個自定義對象ExportType
:創建同一類的不同實例,哪種設計模式?
public class ExportType{
protected String name;
protected FetchingStrategy fetchStg;
protected ExportStrategy exportStg;
public ExportType(String name, FetchingStrategy fetch, ExportStrategy export) {
this.name = name;
this.fetchStg = fetch;
this.exportStg = export;
}
// ...
}
在我的應用程序必須創建具有不同FetchingStrategy
和ExportStrategy
出口類型的列表。通過實施新的FetchingStrategy
和ExportStrategy
,未來可以創建新的導出類型,所以我想設計我的應用程序以儘可能靈活。
有沒有一種設計模式可以用來獲得我所需要的? 爲每個ExportType
創建不同的TypeFactory
特定實例是否是正確的方法?
UPDATE
我試着總結一下我的問題:我正在將數據從一個數據庫導出一個Web應用程序。我有幾種方法從數據庫提取數據(ExportType
s),這些類型是通過FetchingStrategy
和ExportStrategy
的不同組合獲得的。現在我需要創建一個這些「組合」列表來在必要時調用它們。我可以創建這樣的常量:
public static final ExportType TYPE_1 = new ExportType(..., ...);
,但我想實現它的方式,所以我可以在未來的新組合/類型添加。
有靈活性,然後是過度工程。要小心,你不會過分癡迷*使用什麼樣的模式*而不是*你需要解決什麼問題*。你又有什麼問題? – cHao
@cHao你說得對 - 當你說的時候 - 注意你不會太過迷戀patterns_事實上我正在尋找一種方法來減輕我的工作。 :) – davioooh