Ryan,
Here's a simple example of how you code could be structured. The
benefit you get from using getters and setters is that the calling
object never needs to know anything about what processes need to go on
with a variable set. Say you need to salt (add a string to a
password) and then hash it. You setPassword() function could contain
all the logic of how to do that instead of your UI needing to know.
HTH
<cfcomponent hint="I will handle password functions" >
<cfset variables.instance = structnew()/>
<cfset variables.instance.oldPassword = ""/>
<cfset variables.instance.newPassword = ""/>
<cfset variables.instance.newPassword2 = ""/>
<cffunction name="setOldPassword" returntype="void" access="public">
<cfargument name="sOldPassword" type="string" required="true">
<!--- Maybe do some error checking here --->
<cfset variables.instance.oldPassword/>
</cffunction>
<cffunction name="getOldPassword" returntype="string" access="public">
<cfreturn variables.instance.oldPassword/>
</cffunction>
<!--- Repeat the above 2 functions for newPassword and newPassword2 --->
<cffunction name="updatePass" access="public" returntype="numeric">
<!--- Do database processing using
variables.instance.oldPassword,
variables.instance.newPassword,
variables.instance.newPassword2
--->
</cffunction>
Calling template:
<cfscript>
// create a componet object
updatePass = createObject("component","cfcs/password");
// now set the properties from our form
updatePass.setOldPassword(form.OldPassword);
updatePass.setNewPassword(form.NewPassword);
updatePass.setNewPassword2(form.NewPassword2);
updatePass.UID = client.UID;
// now call the updatePass function to update the database
updatePass.updatePass();
</cfscript>
On 5/9/05, Ryan Everhart <[EMAIL PROTECTED]> wrote:
> Can someone provide me with an example of getters and setters with the
> code I provided? I found an example on the web, but I'm still a
> little more than confused.
>
> http://www.daniweb.com/techtalkforums/thread13881.html
>
> > > <cfscript>
> > > // create a componet object
> > > updatePass = createObject("component","cfcs/password");
> > > // now set the properties from our form
> > > updatePass.OldPassword = form.OldPassword;
> > > updatePass.NewPassword = form.NewPassword;
> > > updatePass.NewPassword2 = form.NewPassword2;
> > > updatePass.UID = client.UID;
> > > // now call the updatePass function to update the database
> > > updatePass.updatePass();
> > > </cfscript>
> > >
----------------------------------------------------------
To post, send email to [email protected]
To unsubscribe:
http://www.dfwcfug.org/form_MemberUnsubscribe.cfm
To subscribe:
http://www.dfwcfug.org/form_MemberRegistration.cfm