I’ve got a StoreOwner entity. StoreOwner has a Store property.
public class Product { }
public class Store {
public IEnumerable<Product> Products { get; private set; }
}
public class StoreOwner {
public Store Store { get; private set }
}
I’ve got the following user story:
As a store owner, I can add a product to my store.
Where should the behavior of “adding the product to the store” live? On the StoreOwner or the Store?
If it’s the store, what would the method name be?
I would put it in
Store, as I’m guessing the products collection is a child entity inStore. Something likeStore.AddProduct()as opposed to exposing the products collection.If there is logic to make sure only the current owner can do it, I believe this optionally belongs in
Storeonly ifStorealready has knowledge about the owner, but should definitely be validated before trying to allAddProduct.That part seems like a user role, so perhaps this belongs in your UI controller or if the current user is actually the store owner, perhaps factor this into the user role and authorise against it.