DDD Model Design and Repository Persistence Performance Considerations

Posted by agarhy on Programmers See other posts from Programmers or by agarhy
Published on 2012-10-20T17:11:01Z Indexed on 2012/10/20 17:13 UTC
Read the original article Hit count: 376

So I have been reading about DDD for some time and trying to figure out the best approach on several issues.

I tend to agree that I should design my model in a persistent agnostic manner. And that repositories should load and persist my models in valid states.

But are these approaches realistic practically? I mean its normal for a model to hold a reference to a collection of another type. Persisting that model should mean persist the entire collection. Fine. But do I really need to load the entire collection every time I load the model? Probably not.

So I can have specialized repositories. Some that load maybe a subset of the object graph via DTOs and others that load the entire object graph. But when do I use which? If I have DTOs, what's stopping client code from directly calling them and completely bypassing the model?

I can have mappers and factories to create my models from DTOs maybe? But depending on the design of my models that might not always work. Or it might not allow my models to be created in a valid state.

What's the correct approach here?

© Programmers or respective owner

Related posts about Performance

Related posts about domain-driven-design