Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Ok for Entity to know about the repository?   Topic List   < Prev Topic  |  Next Topic >
Reply | Forward < Prev Message  | 
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




Mon Jun 9, 2008 7:30 am

elbandit33
Offline Offline
Send Email Send Email

Forward
< Prev Message  | 
Expand Messages Author Sort by Date

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...
elbandit33
Offline Send Email
Jun 10, 2008
4:17 pm

Does know (in the real domain) an order how to do a checkout? I guess not and thats the reason that code seems ugly to me. I think something like...
Diego Carrion
dc.rec1
Offline Send Email
Jun 10, 2008
11:46 pm

It seems to be debatable. Eric Evans, 2004: http://tech.groups.yahoo.com/group/domaindrivendesign/message/1225 ... Randy Stafford,, 2005: ...
dddbloke
Offline Send Email
Jun 11, 2008
12:32 am

dddbloke said: It seems to be debatable. Eric Evans, 2004: http://tech.groups.yahoo.com/group/domaindrivendesign/message/1225 ... Randy Stafford,, 2005: ...
John Roth
jhrothjr
Offline Send Email
Jun 11, 2008
12:53 am

I agree with Randy -- I've been putting code in my entities to use Repositories since I began (religiously) using DDD. Could someone explain the dangers of...
Stasko, Roger
rogerstasko
Offline Send Email
Jun 11, 2008
12:59 pm

Roger so would you favor: ShoppingCart.AddItem(product) Public Class ShoppingCart Public Sub AddItem(item as Product) repository.addLine(Me, Product) End Sub ...
elbandit33
Offline Send Email
Jun 11, 2008
1:30 pm

Not Roger but... One way to look at this would be to consider "ShoppingCart" to be your Repository. You wouldn't need a ShoppingCart domain entity nor a ...
Bob Hanson
mnbob70
Offline Send Email
Jun 11, 2008
1:57 pm

Assuming that ShoppingCart is your aggregate entity and Product is a child entity of that aggregate, a ShoppingCartRepository should have the responsibility to...
Stasko, Roger
rogerstasko
Offline Send Email
Jun 11, 2008
4:26 pm

I'm hesitant to revisit this discussion as my original questions resulted in Randy's FAQ answers. I will mention that when first looking at DDD the impression...
Bob Hanson
mnbob70
Offline Send Email
Jun 11, 2008
1:45 pm

I go both ways and I think the answer is "it depends". I have some solutions where entities directly interact with repositories however lately I'm favoring an...
Bil Simser
sim0099
Offline Send Email
Jun 13, 2008
5:57 am

Hi, for me my repository interface(s) is part of the domain model. so my business entities use the interface to access the repository methods. The concrete...
Tchuta leonard
tchuta
Offline Send Email
Jun 11, 2008
1:31 pm

Ditto. And Spring offers the @Configurable annotation to allow AOP injection to your normally non-spring-managed entities. ... business entities use the...
leojhartiv
Offline Send Email
Jun 12, 2008
2:24 pm

Hi Bob, don't entirely agree here. if you use an ORM external mapping file.  you can implement pure POJO for java business entities and pure POCO for C#...
Tchuta leonard
tchuta
Offline Send Email
Jun 11, 2008
2:28 pm

Hi, I would like to know, how do you inject your runtime dependency on repository imlementations into your entities. What's best practice or generally approved...
Sebastian Jancke
sebastian.ja...
Offline Send Email
Jun 11, 2008
6:02 pm

We're still doing dependency injection the old-fashioned way -- with interfaces and factories, and using reflection and external properties where necessary (to...
Stasko, Roger
rogerstasko
Offline Send Email
Jun 11, 2008
7:57 pm

This discussion here <http://tech.groups.yahoo.com/group/domaindrivendesign/message/7420> details quite a few approaches. I personally use Spring's...
kaushik_spock
Offline Send Email
Jun 12, 2008
10:48 am

... AspectJ and I am very happy with it. I am uncertain whether there are any good byte code instrumentation tools for .NET because I haven't developed with it...
sebastian.jancke
sebastian.ja...
Offline Send Email
Jun 12, 2008
1:36 pm

I use the static IoC from Ayende's Rhino Commons. See http://www.ayende.com/Blog/archive/2006/07/30/7390.aspx ... From: Sebastian Jancke...
Mauricio Scheffer
mauriciosche...
Offline Send Email
Jun 12, 2008
2:29 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help