I'm just getting started in DDD, and I'm having some trouble figuring out how to accommodate the relational nature of my data. I have what I believe would be considered my aggregate root, but the aggregate also has an aggregate of its own. Not wanting to violate the Law of Demeter, I'm wondering if I'm thinking about this wrong and am hoping that some DDD expert can offer some insight.
My aggregate root is my Account
object, which has an aggregate of numerous AccountElement
entities, which are themselves logical groupings of individual ProductComponent
entities.
An AccountElement
outside of the context of an Account
has no meaning, so I'm comfortable with my conclusion that the Account
object is my aggregate root, and I anticipate that entity having an aggregate Elements
property. It's the ProductComponent
collection that has me confused. This aggregate has no meaning outside of an AccountElement
, and really has no meaning outside of an Account
.
I don't think I should be accessing individual ProductComponent
objects by dotting my way to it, like:
var reference = account.Elements(0).ProductComponents(0).ReferenceCode;
But at the same time it doesn't make sense (from a domain perspective) to access a ProductComponent
directly from an Account
entity.
I'm sure that this is all a little difficult to comprehend without knowledge of my domain, but I'm hoping it's enough to get some good feedback.
Josh