I have a StoreOwner object. 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 have the following user history:
As a store owner, I can add a product to my store.
Where should the "add to store" behavior occur? In the StoreOwner store or in the store?
If it is a repository, what will be the name of the method?
I would put it in Store, since I assume the product collection is a child of Store. Something like Store.AddProduct(), not for exhibiting a collection.
Store
Store.AddProduct()
, , , , Store, Store , , AddProduct.
AddProduct
, , , , , .
" "? StoreOwner ?
,
, Store. - store.AddProduct(product). , - .
store.AddProduct(product)
One of the best approaches I've taken is to always look at it, who belongs to whom.
So:
StoreOwner owns a store. The store contains a product.
So, based on your story and the above use case, you will say Store.AddProduct (newProduct);
If you only need to be able to add a product, if you have access to the instance StoreOwner, put the method there, otherwise in the class Store.
StoreOwner
The name AddProductseems obvious ...