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