If you want to use CFCs as an extra layer of abstraction though, create a 
Gateway.cfc for your whole application.  Gateway.cfc should have all 
query-related operations in it, and most of the methods should return objects, 
arrays of objects, or simple string/numeric/etc. data.  Load an instance of 
Gateway.cfc in your Application.cfm (or Application.cfc) as an application- or 
server-scoped variable so it only loads into memory once and is shared by all 
calling templates.  Do it like this:

<cfif not IsDefined('application.team')>
  <cfset application.team = CreateObject('component', 'path.to.Gateway')>
</cfif>

During development, it's helpful to comment out the <cfif not IsDefined> stuff 
as that causes the instance to "stick" in memory, even if you change the source 
of the CFC.  This is good in production because CF doesn't need to rebuilt the 
unchanging instance for every page load.

Let's say your entire application is for team management, so maybe you'd name 
the Gateway.cfc instance "application.team".

Your call to application.team.getTeamMembers() would run a query to get all the 
data you need to build the objects you would put into the array.  Loop through 
the query and build your objects as needed.  The objects that get put into the 
array should have no queries built into them.  Return the array of objects.

Douglas's point of the queries being an abstraction in itself is also valid, 
but I mainly construct my code that way only if it's a smaller application.  
Keep in mind that the only way it is an abstraction is if you alias the field 
names, as in

SELECT
  BL_ID AS blahID,
  BL_NAME AS blahName
FROM ...

Hope that helps.


- Chris Peters

>just create a CFC, teamGateway.cfc for example, that returns a query of your 
>team members. The query result is already an abstraction, use it.
>
>DK
>
>On 6/9/05, Cedric Villat <[EMAIL PROTECTED]> wrote:
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:209146
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to