Name
Lazy Load
Goal
To avoid delays created by excessive and unnecessary database access (Figure B-5).
Participants
- Client
Presentation tier or other system component.
- Business object
Business delegate, session façade or other business logic related object.
- DAO
Provides access to the persistence layer.
- DTOs
Objects for exchange of data between participants.
Interactions
The client calls methods on a business object, requesting specific data. The business object calls a DAO method to retrieve only the data required for the current method. If the client needs additional data, the business object performs an additional request to the DAO.
Notes
Implementing the Lazy Load pattern intelligently requires a bit of analysis of your application. If your application can retrieve several kinds of data with a single database query, it will generally be more efficient to do that then to retrieve each piece separately. If multiple queries would be required anyway, and different use cases require different data, the Lazy Load pattern can improve performance by limiting queries to only those strictly necessary.
Get J2EE Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.