CFC - to init or not to init
I have long used custom tags, but now find myself creating components. I am not an OOP developer. I have read various "best practice" articles and am still looking for a compelling reason to add an init constructor to my CFCs. I attach two very simple code examples (test.cfc), the first shows how I currently use CFCs and the second, if I understand correctly, is how I should be coding.
1.
<cfcomponent>
<cfset this.Price = 10 />
<cffunction name="getPrice" output="no" returntype="numeric">
<cfreturn this.Price />
</cffunction>
</cfcomponent>
2.
<cfcomponent>
<cffunction name="init" access="public" returntype="Test">
<cfset variables.Price = 10 />
<cfreturn this />
</cffunction>
<cffunction name="getPrice" output="no" returntype="numeric">
<cfreturn variables.Price />
</cffunction>
</cfcomponent>
