Hello I am a newbie so I do apologise if this question has come up
before, I have scanned through the previous posts but couldn't find
an answer so here goes...
Is it ok to have a reference (via interface) to the repository from
within an entity? I have had a look at this post
http://www.paulgielens.com/archive/2006/08/08/Organizing-Domain-
Logic.aspx
And it shows the CheckOut method of the Order entity talking to the
Repository like so:
public void CheckOut()
{
// Handle credit card logic
customer.CreditCard.Charge(TotalAmount);
// Insert the new order into the system
repository.AddOrder(this);
// Update the inventory stock
foreach(OrderLine line in orderLines)
{
line.Product.TakeStock(line.Quantity);
}
}
This makes sense but I am not sure that it is DDD as I was under the
impression that the domain model should be POCO with no knowledge of
the datastore.
Another example would be a shopping basket:
// The Basket Line object would have to talk to the repository
shoppingBasket.items.Add(product);
vs
// The Service talks to the repository
shoppingBasketService.AddItem(shoppingBasket, product;
vs
// Again The Service talks to the repository
shoppingBasket.items.Add(product);
shoppingBasketService.save(shoppingBasket);
vs
// The Basket Entity talks to the repository - like the example above
from paulgielens
shoppingBasket.items.Add(product);
shoppingBasket.save();
Are all of these valid DDD? If not which is?
I have seen some demo code downloaded from Tim McCarthy's Blog that
also shows the repository accessed from within the Order Entity object
(http://blogs.interknowlogy.com/timmccarthy/archive/2006/12/06/9351.as
px)
I know all of these are simple examples but do they all follow the
same DDD principles?
Thanks for your help
Scott