> Along with many others, I am finally making my journey 
> through the "Object Safari" and after much too long I am 
> finally beginning to get it. The proverbial light is blinking 
> and I am starting to see the forest. For a while I was trying 
> to look at the forest from the trees, but I didn't know that 
> I was in the trees.
> 
> Now that I am a little more ready to start looking at the 
> trees, two sets of code examples I am looking at are causing 
> me to wonder if I should use the VARIABLES scope or the THIS 
> scope in my bean objects.
> 
> Here are two different methods which illustrate it:
> 
>       <cffunction name="setId" access="public" output="false" 
> returntype="void"
>                       hint="Sets this person's ID">
>               <cfargument name="id" type="string" required="true" />
>               <cfset variables.id = arguments.id />
>       </cffunction>
> 
>       <cffunction name="setid" access="public" output="false">
>               <cfargument name="id" required="yes">
>               <cfset this.id= arguments.id/>
>       </cffunction>
> 
> Just a quick note: The accessor method using the VARIABLES 
> scope is an actual bean object while the accessor method 
> using the THIS scope is an uber-object that also contains 
> CRUD and other Gateway methods. I'm not sure if that is 
> influenced the choice to use THIS over VARIABLES or not...

In Java, beans use private member variables, but expose accessors and
mutators in a way that lets you set and get those private member variables
as if they were public. This makes it easy to get and set values, but allows
you to enforce validation rules within the bean, which you couldn't do if
the variables were public.

Since CF doesn't let you do this, you can't really create something directly
analogous to a Java bean in CF. I would recommend instead that you simply
use private member variables, and write accessor and mutator functions as
appropriate, and call those functions (which is what it appears you're
doing).

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
 
Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore and Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:260701
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to