Well, this brings up another issue. I plan to have several different
ways of getting the information into the CFC. One method will be
through a form submission and another is via an import routine. Either
way I have to validate the data coming in. I wasn't sure if I should
validate with the setters or call a validation routine that would go
through all the properties. My plan is to validate with the setters,
catch all the errors thrown by the setters and compile them into a
single message back to the user.
------------------------------------------------
Gerry Gurevich,
Lockheed Martin
[EMAIL PROTECTED]
919-572-7818
Nolan Erck
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
m> cc:
Sent by: Subject: RE: [CFCDev] Best Practices
Question: Getters and Setters
[EMAIL PROTECTED]
one.org
01/07/2004 12:29
PM
Please respond to
cfcdev
You could also write one generic Get/Set method that takes an extra
parameter - the name of the value you're manipulating. Ex:
SetMyVar( "foo", "12" )
<cffunction name="SetMyVar">
<cfargument name="pName">
<cfargument name="pValue">
<cfset this.#arguments.pName# = arguments.pValue>
</cffunction>
<cffunction name="GetMyVar">
<cfargument name="pName">
<cfreturn this.#arguments.pName#>
</cffunction>
The only difference is, you may want to write some sort of error
checking to ensure the variable getting modified is valid, as someone
may mistype the variable name when calling the function.
I've done this before in projects (also in C++ apps) and it worked okay.
hth,
-Nolan
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 07, 2004 9:22 AM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Best Practices Question: Getters and Setters
I have a CFC with 26 properties. None are inherited. I find that
having 52 methods for getting and setting to be a bit cumbersome to keep
in my CFC with the "real" methods. I was thinking of including all my
getters and setters from a CF template. Let's say that the my code
looks like this:
facility.cfc
<cfcomponent hint="I am a facility">
<!--- Include the getters and setters --->
<cfinclude template= "facilitygetset.cfm">
<!--- Start the more complicated stuff --->
<cffunction name="firstrealmethod">
.
.
.
</cffunction>
.
.
.
.
</cfcomponent>
Any thoughts on this as a good idea, bad idea, unintended consequences?
------------------------------------------------
Gerry Gurevich,
Lockheed Martin
[EMAIL PROTECTED]
919-572-7818
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words '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 words '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 words '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]