> When I create an object and init it with data, would I pull in only the
> foreign key ID (1, 2, 3, etc) or do I pull in the value�("B&W",
> "Portrait", "Digital") and store with the rest of the picture object
> properties?
I almost always pass in the foreign key values when initializing an object.
That way, you can use lazy initialization to load the objects and make more
intelligent decisions about how to load the objects at runtime.
However, when building the relationships, I usually work with object
references:
<cfset category.addProduct(product)>
As opposed to...
<cfset category.addProduct(productID)>
The former allows the category object to make whatever decisions it needs to
make (e.g. product.getIsActive()) without having to load the product in a
separate step. It also means that there's less code aware of how products
are related to categories.
My first attempts at OO did not take the approach I'm now advocating, which
meant, for instance, that loading a product forced a load of the category to
which the product belonged even if that information wasn't necessary to
fulfill the request. As you can imagine, performance suffered.
It also meant that a lot more of my code had to be aware of how objects are
related than was absolutely necessary. In the example above, that's not such
a big deal. However, there are instances where relationships are more
complicated or even determined by runtime state.
For instance, product.getThumbnail() might check to see if an explicit image
has been set for a thumbnail. If not, it might check for a full size image,
resize it on the fly, cache the image to disk, etc. If there's not full size
image, it might check to see if there's a default image to display.
Ben Rogers
http://www.c4.net
v.508.240.0051
f.508.240.0057
----------------------------------------------------------
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]