I'm curious to know how others are dealing with this issue:
You want an entity, A, that has associations to B and C. One use case requires that you return just A, another requires you return A w/ Bs, another A w/ Cs.
In the scenarios above, how'd your DAO method(s) look? That is, do you have DAO methods for each use case, like:
Code:
DAO.getA(...)
DAO.getAwithB(...) // has respective B initialization
DAO.getAwithC(...) // has respective C initialization
or are you passing in some loading level flag:
Code:
DAO.getA(..., ALoadingLevel aLoadingLevel) // where aLoadingLevel has boolean properties for each property indicating whether to initialize. Maybe this DAO is using QBE, or fancy HQL building
Currently we have a manageable number of use cases, however, there is anticipated growth scheduled here in the next release. The problem with the second scenario is when we start getting into nested loading levels. Now our aLoadingLevel object gets slightly more complicated. We'd possibly modify this to be a collection of Loading Level objects.
Later on, we decorate our DTO with this same loading level object so that clients won't unknowingly try to load an association that wasn't included in its assembly.
I don't see this best practice addressed anywhere. Is there a best practice out there in the community you'd like to share?