Ok, I'll compare a few ways of doing it (continuing this example).
Regardless of the way your choose, the process is to somehow get the
name to the CFC so that it can insert it into the database as part of
the job.

Way 1) This way puts the name into the THIS scope, from where the
insert method can get it and use it in a DB insert:
newJob.name=form.name;
newJob.insertJob();


Way 2) This way puts the name into the VARIABLES scope via the
setName() method, from where the insert method can get it and use it
in a DB insert:
newJob.setName(form.name);
newJob.insertJob();


Way 3) This way takes the name as an argument, from where the insert
method can get it and use it in a DB insert:
newJob.insertJob(form.name);

My preference is way 2. I can then type check the name in one place,
no matter where I want to use it later - it means I can reuse the
setName() method for other things (not just a subsequent DB insert).
It also controls the alteration of the property, meaning I can enforce
a CFLOCK around it within the method if necessary (I can't necessarily
rely on that with the THIS scope way - I have to hope the person who
set THIS used CFLOCK outside the component instead) but locking is a
whole other discussion :-)

On 2/17/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
> >If you don't want the "name" variable to remain in the CFC between
> method calls, pass it in as per newJob.insertJob(name=form.name).
>
> James, you just added a whole new dimension to my confusion. I know
> you didn't mean to, but what is the difference between setJob() and
> insertJob(). Obviously it must have something to do with the method
> within the cfc, but what? This brings me back to when to use a static
> component vs. instance components and rethinking how I write my
> methods and properties.
>
> I feel like one of those newbies that approaches CFC's, thinks he can
> do it, and then become hammered with confusion as psuedo code is
> flushed out. I just want to push forward and not draw back, but like
> so many others I have deadlines and I am already overdue.
>
> Somebody resue me!
>
> -Aaron
>
> On 2/16/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
> > I am looking at the following article by Rob Brooks-Bilson:
> >
> > http://www.oreillynet.com/pub/a/javascript/2003/09/24/coldfusion_tips.html
> >
> > I know it is an old article, so it may not be up to date with "best 
> > practices."
> >
> > Anyways, I thought I had it down until I was introduced to the
> > psuedo-constructor and instantiation. I thought I could just create
> > arguements in my cfc's with the cfargument tag, and then pass the
> > cfc's the arguments when invoking them. While that is an option, it
> > seems to be the very basic of basic uses of CFC's and I am trying to
> > leverage OOP development the best I can in ColdFusion.
> >
> > I still don't really understand when I should create a static
> > component and when I should create an instance-based component. The
> > CFWACK book is very vaque, and documentation is sparce.
> >
> > Now that you guys are clearifying how to pass an instance component
> > arguments, I am begining to rethink my entire approach to writing
> > methods and properties. I really hate learning the wrong way to do
> > things first, and then learning how to do it right.
> >
> > Any help is very appreciated!
> >
> > -Aaron
> >
> > On 2/16/06, Alan Rother <[EMAIL PROTECTED]> wrote:
> > > I'm sorry, are you asking if you should use the variables scope in the CFC
> > > itself?
> > >
> > > If so, I don't recommend it. using variables.  anything makes that 
> > > variable
> > > available to all of the other methods in the cfc and basically trashes the
> > > thread safeness of the cfc, that is if you are using the cfc in a 
> > > persistent
> > > scope. If you are instantiating the cfc evertime you use it, then it's ok,
> > > but under load it can really start to take a performance hit if you are
> > > invoking on every hit to the page.
> > > --
> > > Alan Rother
> > > Macromedia Certified Advanced ColdFusion MX 7 Developer
> > >
> > >
> > >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:232662
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to