我有一种情况,我正在建模一个域,该域的业务规则是
当用户需要查看类别时,用户应该看到这两个帐户 和商店类别。因为商店继承了类别 主帐户。
将此业务规则包含在保持泛在语言的damain模型中的最佳方法是什么?
这就是我的想法
Store.InheritCategoriesFrom(Account.Categories);
Store.GetAllCategories();
然后在域中的行为函数可以像
public List<Category> AllCategories { get; set; }
public InheritCategoriesFrom(List<Category> AccountCategories)
{
//code to merge Shop.Categories with Account Categories into AllCategories here..
}
public List<Category> GetAllCategories()
{
return AllCategories;
}
如果我错了,请告诉我,为什么?所以我可以开始思考正确的方向。
答案 0 :(得分:1)
When a user needs to see categories.. the user should see both account and store categories.
That's not a business rule, that's a UI view requirement => view model data => can be queried directly from the db and it doesn't have to be one query only.
Because the Store Inherits Categories from the main Account.
That's an implementation detail, it can't be a business rule and a useless detail nevertheless (even harmful) when talking about querying.
Just have a method on your store (or use a query handler) which will return all the data required for the view model. No inheritance needed. Just KISS.