I am new to CFCs and I think I am missing the point of getters and setters A
lot of the text says that when writing a cfc we should write getter and setter
methods but it seems like a lot of extra work and I would like to know what the
benefits are. Why is it not a good idea to set the variables publicly and
access the cfc properties directly? I produced the following cfc:
<cfcomponent hint='I am the son' extends='Dad'> <cfset this.firstName='Rob'>
<cffunction name='getfirstname' returntype='string'> <cfreturn
this.firstName> </cffunction> </cfcomponent> Then I produced the following
test page: <cfobject component='Son' name='sonObj'> <cfoutput>
#sonObj.firstname#<br> #sonObj.getfirstname()#<br> <cfset
sonObj.firstname='Adam'> #sonObj.firstname#<br> #sonObj.getfirstname()#<br>
</cfoutput> Which produced the following output: Rob Rob Adam Adam I
realise that by scoping the firstname with 'this' that I am making it a public
variable which can be accesssed outside the object and that the benifit of
encapsulation is not gained but my question is why is this not done in the
examples of the web? By scoping the property in the 'variables' scope and
writing getters & setters we may get encapsulation but the ability of being
able to change properties remains via the getters & setters. Is it because
setters allow for validation that setting the value publicly does not? But if
so why write getters, they dont require validation. If variables are set
publicly are they open problems that I am not aware of?If so could some one
show me an example. Are there any good articles on the subject?