Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / May 2006



Tip: Looking for answers? Try searching our database.

using CFCs statically without cfinvoke

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JeffeeBoy - 30 May 2006 15:01 GMT
We have a set of CFCs that we use as an application API.
Currently, the way I use them is by instantiating them in the application
scope and then creating aliases (for shortened syntax) like this:
<cfobject name="Application.Company" component="components.company">
<cfset $Company = Application.Company>

and then in the application, I call methods like this:
<cfset qCompany = $Company.GetCompanyDetails(cmpid)>

-- All of the objects are intented to be used statically and have no instance
data, but to use them like this, I've obviously having to create an instance
(using CreateObject or cfobject).
-- The reason I don't use CFInvoke to call methods statically is because I
think that it makes the code much more difficult to read.
-- The one concern I have of using the objects in the way that I am (by
creating instances of them and putting those instances into application scope)
is that if I forget to "var" any variables in a method, then I have just
created "instance data" on the object, and things could get really tough to
debug when unexpected behavior starts occurring in the application.

-- I 'm trying to find a solution to reference my CFCs, and then access them
later statically without creating an instance at all. Has anyone ever come up
with a solution for this?

-- As a "last resort", I could always create the objects in Request scope, but
there's obviously some performance overhead there.

Any thoughts on this?
Fernis - 30 May 2006 16:23 GMT
I think <cfinvoke> is just what you should use. But If the code beautification
is what you're after, you could write a wrapper User-Defined-Function (UDF) for
the <cfinvoke> tag - just like cflib.org's many UDFs, that are meant to replace
the corresponding tags. Put the wrapper functions in a separate file, and
include it from your master template?
Adam Cameron - 30 May 2006 17:31 GMT
> I think <cfinvoke> is just what you should use.

There's a rather large performance hit when creating/destroying CFC
instances (one IS still created when doing a <cfinvoke>, it's just "killed"
immediately after use).

If your CFCs are just "bags o' functions" rather than being used to define
"objects", it might be an idea to forgo using CFCs, and just use UDFs (or
libraries of UDFs, as appropriate).

Signature

Adam

JeffeeBoy - 30 May 2006 18:38 GMT
Thanks for the replies
JeffeeBoy - 30 May 2006 18:38 GMT
Thanks for the replies
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.