1
我ProductRepository Repository模式有一個方法,讓說:混合邏輯
GetAllCalculatedProducs(int categoryId) {}
此方法使用類計算器來計算產品的許多值。它看起來就像這樣:
public IEnumerable<Product> GetAllCalculatedProducts(int categoryId)
{
var items = GetAllProductsByCategoryId(categoryId);
Calculator c = new Calculator(items);
c.Calculate();
Filter f = new Filter(c.Items);
f.Filter();
Sorter s = new Sorter(f.Items);
s.Sort();
return s.Items;
}
計算器使用另一個存儲庫的工作。
[DB] < - > [存儲庫] < - 商業邏輯| - > [Calculator]
我認爲這是錯誤的,因爲Repository使用屬於Logic的類。我甚至認爲這種方法應該可以在其他地方使用ProductService?但我不確定。
並且Filter和Order可以在倉庫中使用嗎?
感謝您的回覆,所以解決方案可能是這樣的:http://pastie.org/1859961,對吧? – reizal 2011-05-03 10:54:40
是的。儘管我會爲'Sorter','Filter'和'Calculator'使用更具體的名稱。也許'SortOnLastName','FilterOutOldEntries','CalculateAveragePrice'。 – jgauffin 2011-05-03 11:04:07
很好,謝謝你的建議 – reizal 2011-05-03 13:20:12