In Coldfusion, why do we expose private CFC variables to the world, using setters & getters?
Now, I know this question may sound dumb, because every expert, in this field, advocates such an approach, but I would like to understand why? Surely, if one sets 'variables.name' in a CFC, it should remain private. Looking at this the other way around, why don't we just set 'this.name', and then we don't have the overhead of having to create a setter & getter method. Although, I realise that Coldfusion has improved this issue by providing us with implicit setters & getters, this still doesn't answer the fundamental question.
I keep being told that this breaks the golden rule of encapsulation. But doesn't exposing a private CFC variable via a public method, break this rule, anyway?
Then, other people have told me that it is about controlling access. But how is this controlling access, when public setter & getter methods, are exposed to all & sundry?
Accessing a private CFC variable value via a public method, seems like a lot of hard work to me, especially if you have hundreds of private variables. Why not just access a public CFC variable directly?
Inside user.cfc:
<cfset this.name = "foo" />
<cfset variables.name = this.name />
<cfset var name = this.name />
Outside user.cfc [another CFC or CF template]
<cfset user.name = "foo" />
<cfset variables.name = user.name />
Any help on this issue, would be much appreciated...