Learning CF9: Implicit Getters and Setters
Posted on October 18, 2009 at 2:50 PM in ColdFusion
One of the (many) really nice features of CF9 is the addition of implicit getters and setters for CFCs. While I love having a concrete API, I am learning to love this idea more and more because of the saved keystrokes.
Housekeeping
Before we go any further, let me go ahead and say it:
Yes, I know that in the purest form, what CF9 calls "implicit getters and setters" is not actually accurate. However, for the sake of simplicity and continuity with the CF9 documentation, I am going to use the term "implicit". If you don't like it, get over it.
What Implicit Getter/Setter Does
According to the CF9 docs...
"By default, properties that you specify by using the <cfproperty> tag have implicit setPropertyName and getPropertyName methods that access the PropertyName property in the CFC variables scope."
Translation: If you have the following...
- <cfproperty name="Foo" />
... CF9 will automatically generate the following two methods for you:
- <cffunction name="getFoo">
- <cfreturn variables.foo />
- </cffunction>
- <cffunction name="setFoo">
- <cfargument name="foo" />
- <cfset variables.foo = arguments.foo />
- </cffunction>
However, the documentation is wrong. Perhaps "wrong" is too strong a word, but the docs are certainly inaccurate and incomplete. In order to actually get CF9 to behave in this manner, you must also add the 'accessors' attribute to your <cfcomponent> tag.
- <cfcomponent accessors="true">
With this in place, CF9 will now generate the get/set{Property} methods for you on properties that you have defined with <cfproperty>.
Latest Articles
- No recent entries.
Categories
- ColdBox (21) [RSS]
- ColdFusion (92) [RSS]
- Fusebox (3) [RSS]
- General (22) [RSS]
- jQuery (15) [RSS]
- Kalendar (1) [RSS]
- Linux (1) [RSS]
- Mura CMS (1) [RSS]
- Railo (1) [RSS]
- Rants (5) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (36) [RSS]



There are no comments for this entry.
[Add Comment]