I have a situation where I am modelling a domain, the business rule of the domain is that
When a user needs to see categories.. the user should see both account and store categories. Because the Store Inherits Categories from the main Account.
What would be the best way to include this business rule in the damain model keeping Ubiquitous Language in mind?
here is what I had in mind
Store.InheritCategoriesFrom(Account.Categories);
Store.GetAllCategories();
and then in the behavior function in the domain can be like
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;
}
Please let me know if i am wrong and why? So I can start thinking in the right direction.
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.
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.