Would it be acceptable practice to add a load and save method in an object which worked in conjunction with a DAO to persist the object in the database?
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Rogers Sent: Wednesday, May 25, 2005 12:35 PM To: [email protected] Subject: RE: [CFCDev] object composition - which method is better in coldfusion? Well, that would depend a lot on whether or not you have a data abstraction layer as well as any caching and such that you have. A simple example (assuming you have DAOs), would be: <cfcomponent name="OrderItem"> <cfset instance = structNew()> <cfset instance.itemID = 0> <cffunction name="getItemID" access="public" returntype="numeric" output="no"> <cfreturn instance.itemID> </cffunction> <cffunction name="setItemID" access="public" returntype="numeric" output="no"> <cfargument name="itemID" required="true" type="numeric"> <cfset instance.itemID = arguments.itemID> </cffunction> <cffunction name="getItem" access="public" returntype="Item" output="no"> <cfset var itemDAO = createObject("component", "ItemDAO")> <cfset var item = itemDAO.read(getItemID())> <cfreturn item> </cffunction> </cfcomponent> Ben Rogers http://www.c4.net v.508.240.0051 f.508.240.0057 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Joe Ferraro > Sent: Wednesday, May 25, 2005 12:28 PM > To: [email protected] > Subject: RE: [CFCDev] object composition - which method is better in > coldfusion? > > Interesting, > > Tell me more about the getItem function how does it interface with the > database? > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Ben Rogers > Sent: Wednesday, May 25, 2005 11:19 AM > To: [email protected] > Subject: RE: [CFCDev] object composition - which method is better in > coldfusion? > > If you use an array of objects, then each OrderItem can calculate it's own > total (quantity * unitPrice = price), calculate it's own weight and return > references to other objects (orderItem.getItem() would return the actual > item in the store/catalog). Then, when you need to calculate your order > total, you can loop through the OrderItems and sum up the total. > > Ben Rogers > http://www.c4.net > v.508.240.0051 > f.508.240.0057 > ________________________________________ > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf > Of Joe Ferraro > Sent: Wednesday, May 25, 2005 11:25 AM > To: [email protected] > Subject: [CFCDev] object composition - which method is better in > coldfusion? > > I have an order object, in ColdFusion which method is better for > composition > of this object. > > Attribute orderItems - array of structures > > Or > > Attribute orderItems - array of orderItem objects > > The average number of order items is 3 and with an occasional high of 20. > > What are your thoughts? > > > > ---------------------------------------------------------- > 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] > > > > > > ---------------------------------------------------------- > 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] ---------------------------------------------------------- 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] ---------------------------------------------------------- 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]
