對不起,我只是不知道如何正確的說話。你有這些方法的工廠嗎?類型或工廠中的靜態方法?
說我有一類叫做表和這三種方法:
//Creates a new table in underlying provider and returns new Table object.
CreateNew(string Name);
//Opens the table in provider and returns new Table object.
OpenTable(string Path);
//Same action as above just on a collection, and returns a IList<Table>
OpenTables(IList<string> path);
在我使用這樣的事情,所有的方法都是靜態的類型當前時間:
Table tab = Table.OpenTable("SomePath");
Table tab = Table.CreateNew("DummyTableName");
你明白了。
但是我想知道這些是否應該在工廠。事情是這樣的:
TableFactory factory = new TableFactory();
Table tab = factory.CreateNew("DummyTableName");
Table tab = factory.OpenTable("SomePath");
工廠不會是靜態的,因爲這將使得使用一個工廠難以測試
你覺得還有什麼其他的代碼?
打開一個表格需要一個底層提供者來調用,所以如果我只是使用了一個構造函數,我就會打破「在構造函數規則中沒有工作」。 – 2009-06-17 04:02:05