On Friday, Jul 25, 2003, at 16:38 US/Pacific, Cohen, Michael wrote:
I might be wrong, but I don't remember seeing that distinction in any of the
DevNet articles. I wonder why that is.

I'll mention it to the DevNet team.


Is it correct that <cfobject> or createObject is the only way to instantiate
a stateful CFC, and that <cfinvoke> simply calls a method of a stateless
CFC?

You can use cfinvoke to call methods on a stateful CFC instance too:


        <cfset x = createObject("component","foo") />
        <cfinvoke component="#x#" method="bar" />
        <cfinvoke component="#x#" method="doo" />

After the recent discussion of 'init()' methods and having them return "this", it's worth noting that you can use that to create new instances via cfinvoke:

        <cfinvoke component="somecfc" method="init"
                returnvariable="x" />
        <cfinvoke component="#x#" method="foo" />

Why? Because the first cfinvoke creates an instance of somecfc and then invokes 'init()' on it - which returns the entire cfc (by reference - that's what "this" effectively is).

That means the following two lines are equivalent:

        <cfset x = createObject("component","foo").init() />
        <cfinvoke component="foo" method="init" returnvariable="x" />

Also, is this discussion of 'stateful' vs 'stateless' CFCs what the heated
"scalability/MVC" discussion was in reference to? That 'stateful' CFCs
require more overhead than 'stateless' ones?

Not necessarily, since both types can be cached to some extent...


Finally, can someone provide a practical example of when 'stateful' CFCs
would be particularly useful?

...how about a shopping cart CFC held in session scope? The cart maintains a list of items in the user's cart and has operations to add new items, adjust quantities and remove items etc.


Sean A Corfield -- http://www.corfield.org/blog/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

Reply via email to