|
Hey
Paul,
I've
been wrestling with the same question lately and I've concluded that you
shouldn't paint your entire application with the same brush. Meaning, it's
really a case-by-case decision.
Here
are some options for you:
<!--- option 1 --->
<cfscript>
myCustomerControllerInstance = CreateObject("component",
"customerController");
customerStruct =
myCustomerControllerInstance.getCustomer(checkCustomer.customerID);
</cfscript>
<!--- option 2 --->
<cfobject component="customerController"
name="myCustomerControllerInstance"/>
<cfinvoke method="getCustomer"
component="#myCustomerControllerInstance#"
customerId="#checkCustomer.customerID#"
returnVariable="customerStruct"/>
<!--- option 3 --->
<cfinvoke method="getCustomer"
component="customerController"
customerId="#checkCustomer.customerID#"
returnVariable="customerStruct"/>
<!--- option 4
---> <cfinvoke method="getCustomer"
component="customerController"
returnVariable="customerStruct">
<cfinvokeargument
name="customerId" value="#checkCustomer.customerID#"/>
</cfinvoke>
Options 1 and 2 are instantiating a copy of
the component in your Variables scope. These are useful if you're planning
on using more than one method in the component during the request so that you
only have to hit the file system once.
Options 3 and 4 are hitting the file system
to read the component into memory. Sometimes this is appropriate, and
other times it isn't. It depends on a lot of factors.
I would only use option 4 if
you're going to optionally pass an argument. Option 3 is almost always
possible, and it's quicker to type and easier to read.
In my opinion, Option 1 is not really a good
idea since CF is not a strictly typed language. Future developers will
have to read through your CFCs to fully understand what you're doing if your
variable names aren't clear. I would only use this option for methods that
have 0 arguments.
So, what it boils down to for me, is options
2 and 3. 1 and 4 are good to know about, and they're handy from time to
time, but generally they should be avoided unless you've got a really good
reason to use them.
Just my $0.02..
- j.
|
- [CFCDev] CFINVOKE vs. CFOBJECT -- which way and why? Paul Giesenhagen
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which way and... Jay Gibb
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which way... Leo Schuman
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which... Dave Cordes
- Re: [CFCDev] CFINVOKE vs. CFOBJECT -- which way... Marcantonio Silva
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which... Barney Boisvert
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which way and... Knight, Matt
- RE: [CFCDev] CFINVOKE vs. CFOBJECT -- which way and... Hardy Jonck
- Re: [CFCDev] CFINVOKE vs. CFOBJECT -- which way and... Rob Brooks-Bilson
- Re: [CFCDev] CFINVOKE vs. CFOBJECT -- which way... Marcantonio Silva
- [CFCDev] Length of a CFC Dave Cordes
- RE: [CFCDev] Length of a CFC Barney Boisvert
