I have a project that is using Spring and is broken down into a couple dozen DAOs and associated DTOs. I'm using JdbcTemplate, but not much else, as it's exactly the level of abstraction I'm happy with.
I'm currently performing lazy loading on my DTOs by placing some rather hairy code in their getters.
Basic boilerplate logic is: 1. If field is not null return its value and exit 2. Contact appropriate DAO and fetch relevant DTOs 3. Store them until next time.
It works fine except that my lowly DTOs are coupled with a whole bunch of DAOs and aren't so POJOey.
Another code smell appears if I place the logic in the DAO since it would be handling both CRUD for its DTOs and Lazy Loading, and as I understand it Objects should have a single responsibility.
I'm hoping that there's a relatively simple Spring approach that I can use to inject a Lazy Loader object between the DAOs and the DTOs to achieve this, but any other solution would work for me.
Any ideas?