> instance.userID = userIDValue; > instance.familyName = getUser.familyName;
Ok. this sounds good usage... but still it looks kinda messy compared to Java OOP. > As for returning "VARIABLES" -- this is something that should be done very > rarely and only when you need to abstractly do things like build a clone or > serialize method. How else would you return Instance data back to the Controller/View, if need to... <cfReturn variables /> --> Would return all the extra stuff of the Instance.. Yes. <cfReturn variables.instance /> --> would be better usage in this case. So essentially, are u saying the below is the apt usage? <cfcomponent> <cfset variables.instance = structNew() /> <cfset variables.instance.firstName = "" /> <cfset variables.instance.lastName = "" /> <cfFunction name="init" access="public" returntype="struct" output="false"> <cfset variables.instance.firstName = "Bob" /> <cfset variables.instance.lastName = "Smith" /> <cfReturn variables.instance /> </cfFunction> </cfcomponent> Joe ----- Original Message ----- From: "Nathan Dintenfass" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 07, 2003 10:55 AM Subject: RE: [CFCDev] Variable referencing in CFCs > I am indeed saying that you should not use "this" to hold your instance > data. There was some justification for in 6.0 because the VARIABLES scope > was broken, but in 6.1 that justification is gone. > > Your second alternative would be more aptly: > > variables.userID = userIDValue; > variables.familyName = getUser.familyName; > > I actually go one step further in most of my CFCs because the VARIABLES > scope itself contains all of the CFCs methods as well as the THIS scope, so > in my init method I like to do: > > variables.instance = structNew(); > > I then would have: > > instance.userID = userIDValue; > instance.familyName = getUser.familyName; > > As for returning "VARIABLES" -- this is something that should be done very > rarely and only when you need to abstractly do things like build a clone or > serialize method. One of the main reasons I like to use "instance" as a > sort of virtual scope is so that when I need to grab all the instance data > at once I don't have to worry about the extra baggage that the entire > VARIABLES scope has (and it's often easy to duplicate() the "instance" scope > [unless it has other CFC instances in it], which for a clone or serialize > method is typically better since it passes by reference if you don't). I > also find the code reads more intuitively when I say "instance.variable", > but that's a personal preference. > > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > Behalf Of Joe Eugene > > Sent: Monday, October 06, 2003 9:44 PM > > To: [EMAIL PROTECTED] > > Subject: RE: [CFCDev] Variable referencing in CFCs > > > > > > Nathan, > > > > I am not sure who wrote Pet Market for MM. Have you ever taken > > a look at the User.CFC? > > > > <!--- PetMarket ---> > > <cfscript> > > this.userid = this.userid; > > this.familyname = getUser.familyname; > > this["billing"]["firstname"] = getUserBillingAddress.firstname; > > ..... > > > > Are u saying the above should be replaced with > > > > <cfscript> > > userID = userIDValue; > > familyName = getUser.familyName; > > > > and > > > > <cfReturn variables> > > would return instance data of the CFC? > > > > Joe Eugene > > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > Behalf Of Nathan Dintenfass > > > Sent: Monday, October 06, 2003 3:02 PM > > > To: [EMAIL PROTECTED] > > > Subject: RE: [CFCDev] Variable referencing in CFCs > > > > > > > > > Yes and Yes. > > > > > > Rule of Thumb (knowing all rules are made to be broken): If you > > > type "This." > > > in a CFC you are probably doing something wrong. > > > > > > > > > > > > > -----Original Message----- > > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > > Behalf Of Adam Wayne Lehman > > > > Sent: Monday, October 06, 2003 11:54 AM > > > > To: [EMAIL PROTECTED] > > > > Subject: RE: [CFCDev] Variable referencing in CFCs > > > > > > > > > > > > <cffunction name="myCFC"> > > > > <cfscript> > > > > VARIABLES.myVar = "false"; > > > > THIS.myVar = "true"; > > > > </cfscript> > > > > <cffunction name="myMethod"> > > > > <cfreturn myVar> > > > > </cfunction> > > > > </cffunction> > > > > > > > > So Nathan, are you saying that these are two separate variables? If so > > > > does that mean myMethod() would return false? > > > > > > > > Adam Wayne Lehman > > > > Web Systems Developer > > > > Johns Hopkins Bloomberg School of Public Health > > > > Distance Education Division > > > > > > > > > > ---------------------------------------------------------- > > > You are subscribed to cfcdev. To unsubscribe, send an email > > > to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' > > > in the message of the email. > > > > > > CFCDev is run by CFCZone (www.cfczone.org) and supported > > > by Mindtool, Corporation (www.mindtool.com). > > > > > > An archive of the CFCDev list is available at > > > www.mail-archive.com/[EMAIL PROTECTED] > > ---------------------------------------------------------- > > You are subscribed to cfcdev. To unsubscribe, send an email > > to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' > > in the message of the email. > > > > CFCDev is run by CFCZone (www.cfczone.org) and supported > > by Mindtool, Corporation (www.mindtool.com). > > > > An archive of the CFCDev list is available at > > www.mail-archive.com/[EMAIL PROTECTED] > > > > ---------------------------------------------------------- > You are subscribed to cfcdev. To unsubscribe, send an email > to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' > in the message of the email. > > CFCDev is run by CFCZone (www.cfczone.org) and supported > by Mindtool, Corporation (www.mindtool.com). > > An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED] ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
