Re: The wisdom of the object mentors (Was: Searching OO Associations with RDBMS Persistence Models)
Date: 20 Jun 2006 11:36:46 -0700
Robert Martin wrote:
> On 2006-06-13 13:22:40 -0400, "Marshall" <marshall.spight_at_gmail.com> said:
> > Can you state what the benefit of lazy loading is?
> Yes. There are two that I can think of on the spur of the moment.
> 1. We don't pay for what we don't use. i.e. if some very late decision
> means that we don't need the data, we don't have to fetch it.
This is also an attribute of simple querying. Don't need the data? Don't query it. Lazy loading doesn't help this at all. This is a non-problem.
> 2. Separation of context and action. It often takes a lot of work to
> figure out the context required to make a query. By the time we are
> ready to make the query we know we have all the context. However, we'd
> rather that the module that does the query have no idea about the
> context. So we use lazy loading to make sure that all the context is
> gathered at the point when the data is accessed.
Okay, the word "context" is pretty broad, so I'm going to substitute a more precise word, parameter, that is my best guess as to what you specifically mean. If I get that wrong, please let me know what other specific thing you did mean.
"It often takes a lot of work to figure out the parameters required to make a query. By the time we are ready to make the query we know we have all the parameters. However, we'd rather that the module that does the query have no idea about the parameters."
So you write a parameterized query. This is a non-problem. Alternatively, you put the query in a method, and have the parameters to the query be the parameters to the method.
Lazy loading doesn't solve any problems that applications using dbmss must have. The only problems it fixes are iatrogenic ones.
Note that this is not the case for other, less general kinds of interfaces. There *are* contexts in which lazy loading is a useful technique. Database access is not one of them, however.
Marshall Received on Tue Jun 20 2006 - 20:36:46 CEST