Instantiating, returning object references, and destinations
Here's something I'd like to gain a better understanding of, because I'm looking for anything that will speed up my processes. I will try to describe and pseudo-code this as well as I can. Apologies in advance if anything is unclear.
I have a CFC that is instantiated and utilized in two different ways. In the first way, the object is created, and a method within it is immediately invoked inline, which initializes some properties within that object, and finally returns This. The transient local object reference is then used to invoke other methods within it, and then it's abandoned as the request runs it normal course.
myLocalObject = CreateObject("component", "myCFC").setStuff(theseArgs);
if (myLocalObject.checkStuff(thoseArgs))
myLocalStruct = myLocalObject.makeStruct();
In the second way, the object is created blindly, and the object reference is stored in a property of the calling CFC. Later, that stored object reference is used to invoke the same setStuff() method, but here I don't care about the object reference being returned by that method, and so I do not provide a destination variable for it.
This.myStoredObject = CreateObject("component", "myCFC");
...
This.myStoredObject.setStuff(theseArgs);
if (This.myStoredObject.checkStuff(thoseArgs))
This.myStoredStruct = This.myStoredObject.makeStruct();
There are additional esoteric operational details relating to both usage scenarios which make doing things one way or the other sensible. So, without looking for answers regarding whether or not I should rethink how my objects are instantiated, I want to know more about how CF performs when a component method is returning a reference to the containing component, but that returned value has no destination. Should I always provide a destination, even if it's just a dummy variable? Or should this even be a concern of mine? Ultimately, I suppose I would feel better if the setStuff() method never bothered to return This, if I was invoking it as a void command, rather than a function returning a value. I'd just like to hear from the forum members whether what I am doing here should be changed in any way, to avoid any inefficiencies.
Thanks!
Christopher
