views:

39

answers:

1

I'm using C++ (with the Qt library) to make a simple domain modeled application. I am writing my own O/R mapping classes. As this application will grow in the future I'm trying to keep a clean codebase with clearly separated layers.

The problem I am having is when and where to load aggregate roots that are referenced in an object in another module. (I am using Eric Evans' use of the word "module" here, from the DDD book.)

I currently have a simple object called Client that sits in the ClientModule module. In the PermitModule I have a Permit object. (the reality is more complex but for brevity I'll stick to those two objects, since they are the aggregate roots) The Permit object has a reference to a Client as applicant. This is my domain model.

From the bottom up, I have an Infrastructure Layer that contains O/R mapping classes and concrete implementations of Repository objects. So I would have a ClientMapper, ClientRepositoryDb, PermitMapper, and PermitRepositoryDb classes here.

Next is the Domain Layer that contains the domain model (Client and Permit classes) plus the repository interfaces ClientRepository and PermitRepository.

Above that I have an Application Layer and then a Presentation Layer but those don't matter in this example.

My question is should the relationship between Permit and Client be loaded in the PermitMapper class or in the PermitRepository class. Or is there some other way of doing it?

This goes not only for loading objects but also for saving them and removing them.

A: 

I've gone with the approach that my Mapper classes load themselves fully.

I'm not a Java developer but I wonder how Hibernate (et al) does it?

darkadept