Back to the idea of using instance variables vs. using getter methods
within the CFC, keep in mind that if the getter method returns an
instance variable that is an array, you're getting a pass-by-value
copy of the array and not a reference to the original array. This can
lead to some bizarre things if you aren't aware of it, like trying to
modify the array returned by the getter but the actual instance
variable doesn't change.


On Mon, 03 Jan 2005 14:56:39 -0700, Nathan Strutz <[EMAIL PROTECTED]> wrote:
> Personally, I like to use the raw instance variables, as it's easier to
> avoid the recursive caller mistake:
> 
> function validateName() {
>    return yesNoFormat(len(getName()));
> }
> function getName(str) {
>    if (not validateName()) {
>      variables.instance.name=retrieveNameFromDB();
>    }
>    return variables.instance.name;
> }
> 
> getName calls validateName, and vice versa. of course this is much
> harder to debug when your cfc is doing a lot more.
> 
> -nathan strutz
> 
> 
> Barney Boisvert wrote:
> > This (or something very similar) has come up before.  I personally
> > like using the getters and setters everywhere, as they are the 'real'
> > properties of the CFC, not the instance variables.  At least that's
> > the theory.  As for overhead, there definitely is some, but it's going
> > to be quite minimal, and can be safely ignored, IMHO.
> >
> > cheers,
> > barneyb
> >
> > On Mon, 3 Jan 2005 15:17:46 -0600, Dawson, Michael <[EMAIL PROTECTED]> 
> > wrote:
> >
> >>I have a simple CFC that has a few instance variables in it.
> >>
> >><cfcomponent>
> >><cfset variables.instance = structNew()>
> >><cfset variables.instance.firstName = "">
> >><cfset variables.instance.lastName = "">
> >>
> >>...
> >>
> >></cfcomponent>
> >>
> >>In this component, I have the pairs of getters and setters such as:
> >>
> >><cffunction name="setFirstName">
> >>...
> >></cffunction>
> >>
> >><cffunction name="getFirstName">
> >>...
> >></cffunction>
> >>
> >>I also have a validate method that needs to check the values of the
> >>instance variables.  Which is the "better form" of accessing the
> >>instance varibles?
> >>
> >>1. <cfif not len(variables.instance.firstName)>...</cfif>
> >>Or
> >>2. <cfif not len(getFirstName())>...</cfif>
> >>
> >>At first glance, the second option is shorter and would still
> >>encapsulate any logic even inside its own CFC.  Would there be any
> >>substantial overhead with calling a method over an instance variable?
> >>
> >>Thanks
> >>M!ke
> >>
> >
> >
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Silver Sponsor - New Atlanta
http://www.newatlanta.com

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189210
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