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:189178
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=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to