views:

266

answers:

2

Is it okay to get a read-only collection from an aggregate without going through the root to get it? My model does some of this right now and I was wondering if that's an acceptable design. Thanks

Edit:

Here's an example

I have an aggregate root entity called UserAccount and another aggregate root called VideoStore. Users can have multiple stores they are apart of and video stores can have many users. A very basic many-to-many, but it's not because the many-to-many bridge table contains state information so it has to be an entity as well. So, I have an bridge entity called UserVideoStores and its a child of the aggregate root VideStore (one-to-many).

Now when a user logs in I want to lookup which VideoStores they are apart of and display that info to them. I can easily do this by making the UserAccount entity have a direct (one-to-many) reference to the child, UserVideoStores, of the aggregate root VideoStores. It seems easier to do this then have to use an HQL query and search from the bottom of the graph up to find which stores the user is apart of.

Does that make sense?

Edit:

Well I came up with a solution to make my model cleaner. I wasn't thinking straight about some of my designs and I learned how to use nHibernate a little bit better to help me come up with a solution. Thanks

+1  A: 

Evans says "The root is the only member of the AGGREGATE that outside objects are allowed to hold references to..." (p. 127)

My understanding is that the aggregate should appear as a unit to outside objects. Also, the Law of Demeter would seem to apply. Bottom line, I don't think it's acceptable.

Robert
Yeah, you are right. I was breaking some laws with that design. I probably need to read Evan's DDD book. It would probably help me out a lot. Thanks
CalebHC
A: 

Actually Eric has changed his mind about the strictness of the Aggregate Root Rules.
He recently said something along the lines of

"Chill out dude. Try to stop yourself from breaking the rules man. But, hey, don't beat yourself up over it. DDD rocks dude, but break the Agg rules if ya really need to. Yeah, peace."

See: "Eric Evans: What I've learned about DDD since the book" http://domaindrivendesign.org/library/evans_2009_1

JW