|
This is how I see it <cffunction name="load" access="public"
output="false" returntype="void"> <cfset var orderDAO = createObject('component','blah.orders.orderDAO')> <cfset var order =
orderDAO.read(variables.instance.orderNumber)> <cfset this.init(argumentCollection=order.getInstance())> </cffunction> <cffunction name="save" access="public"
output="false" returntype="void"> <cfset var orderDAO = createObject('component','blah.orders.orderDAO')> <cfif orderNumber eq ""> <cfset order.insertOrder(this)> <cfelse> <cfset order.update(this)> </cfif> </cffunction> I actually will only be using the load method because the objects are
handed off to the inventory management system for persistence but here it is
for illustration. Does this look good? -----Original Message----- What do you have in mind? You can put your CRUD methods right in your business object, if that's what you're asking. A common name for this pattern is Active Record. Active Record is a far simpler approach than building a data
abstraction layer. As I found out recently, it's also a heck of a lot easier to
explain to people who are not already familiar with DAOs or Mappers, Gateways
and Finders, Transport Objects, etc. The downside is, of course, that your SQL is in your business object.
So, if you need to support two different types of databases (or an XML store), you'll need to duplicate your business objects or move your SQL out
into DAOs. Depending on the size and complexity of your code base, this
could be relatively easy or major undertaking. That said, very few applications need to support multiple types of databases. Often, I create a data abstraction layer simply because it shortens up my business objects. I also auto generate most of the code in the data abstraction layer.
Keeping that code in separate components means it's easier for me to diff and
merge generated code into the components. 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 4:34 PM > To: [email protected] > Subject: RE: [CFCDev] object composition - which method is better
in > coldfusion? > > 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] ---------------------------------------------------------- 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] |
- Re: [CFCDev] object composition - which method is better... Doug Keen
- Re: [CFCDev] object composition - which method is better... Kwang Suh
- Re: [CFCDev] object composition - which method is better... Patrick McElhaney
- RE: [CFCDev] object composition - which method is b... Ben Rogers
- Re: [CFCDev] object composition - which method is b... Patrick McElhaney
- RE: [CFCDev] object composition - which method is better... Joe Ferraro
- RE: [CFCDev] object composition - which method is better... Joe Ferraro
