_Patterns of Enterprise Architecture_ by Martin Fowler describes four
ways to implement Lazy Load.

But another option may be to dig your way out of the need for Lazy Load.

If everything is modelled the most natural way, you may have a Store
with Customers with Orders with LineItems. It's easy to get to the
point where in order to load one object you have to load the whole
database (or resort to Lazy Load). My life got much easier the day I
realized I don't have to model all of those relationships.

For example, instead of getting LineItems from Order, go directly to
LineItemsDAO to get the LineItems when you need them. Order won't know
what its LineItems are, but that might work out just fine.

Often, I'll find that Order does need to know what its LineItems are,
but it doesn't need to change them. (For example, I might need to
print the order with all of its LineItems.) If that's the case, Order
might have a query of line items instead of an array of LineItem
objects.

Sometimes I find that I need to update all of my LineItems for an
order at once. I never deal with them one at a time. Naturally, I'll
put methods for manipulating line items on Order. Since I'm not
manipulating line items directly, I don't necessarily need a LineItem
object. Order could store LineItems internally as, say, a an array of
structs.

Patrick



-- 
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to