> Right now, I'm giving serious thought to breaking the SQL CFC up into
> multiple separate CFC's (one for each primary area of functionality);
> i.e. one CFC for the content management section, one for logging, one
> for user management/login/etc., etc. which would leave me with about
> 10 separate CFC's but would have me touching every single page that
> calls the SQL CFC (I'm using cfinvoke).

Hi Pete, 

I'd recommend that approach in general, but not specifically for
performance reasons. I'd be more concerned about breaking it up into
separate components mostly because the one you have is 4,000 lines.
Although I know there are people who maintain code of that size I've
never considered it a "best practice". 

Aside from the fact that some editors have a difficult time handling
large files like that, it also makes swapping out discrete behaviors
more difficult because the way to swap out some alternative logging
functionality for a specific client (as a random example) would mean
extending that CFC with not just the logging, but all the other stuff
also. 

And for me personally I just find editing really large files to be kind
of frustrating. I generally start looking for ways to split them up once
I get over a few hundred lines. 

However, splitting them up doesn't necessarily have to involve editing
all the rest of your app. There are some tricks you can try to make the
component you have remain the "black box" facade through which data
access happens. One way you might try if you're using CF8 is to use
onMissingMethod to dynamically load the individual functions. 

<cfcomponent>
  <cfset here = getDirectoryFromPath(getCurrentTemplatePath()) />
  
  <cffunction name="onMissingMethod" access="public" output="false">
    <cfargument name="methodName" type="string" required="true" />
    <cfargument name="methodArgs" type="struct" required="true" />
    <cfset var result = "" />
    <cfset var x = 0 />

    <cfif fileExists(here & lcase(methodName) & ".cfm")>
      <cfinclude template="#lcase(methodName)#.cfm" />
    </cfif>
    
    <cfinvoke method="#methodName#" returnVariable="result">
      <cfloop item="x" collection="#methodArgs#">
        <cfinvokeargument name="#x#" value="#methodArgs[x]#" />
      </cfloop>
    </cfinvoke>

    <cfif isDefined("result")>
      <cfreturn result />
    </cfif>
  </cffunction>
</cfcomponent>

Then put each method in its own file in the same directory and viola!
Lazy-loading methods. I haven't tested this sample code at all, but the
onTap framework does something similar for its libraries. So this ought
to work after a little testing if you want to go that route. You might
want to leave a few of the most frequently used functions in the
original CFC though, because pulling them out like this adds to the load
time when the method is called -- so the ones that are most likely to
execute on each request will load faster if you leave them in. 

hth




-- 
s. isaac dealey  ^  new epoch
 isn't it time for a change? 
     ph: 781.769.0723

http://onTap.riaforge.org/blog



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314380
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to