9

I have been building a list of CFC best practices to share.

There are a numerous of articles out there but I thought it might be neat to get any tricks and tips together here in one place that have been learnt through experience.

I'll add a few links here to get it going but I think the best thing would be not long articles that can be googled.

CFC Best Practices

Macromedia CFC Best Practices

Update: This has been made into a community wiki

Peter Boughton
  • 102,341
  • 30
  • 116
  • 172
Jas Panesar
  • 6,599
  • 3
  • 34
  • 45
  • 1) Always ensure your results are reproducible before you notify the press... – Shog9 Mar 06 '09 at 19:00
  • This seems like a community wiki sort of question, perhaps? Eitherway, I'd like to petition for an improved name, since I object to using "best" when a more accurate word is usually "recommended" or "fashionable", since what is "best" is almost always a matter of context. – Peter Boughton Mar 06 '09 at 19:14
  • Are you just looking for ("short") articles that describe best ("recommended") practices? What kind of "answers" do you want? It's kind of unclear... – Adam Tuttle Mar 06 '09 at 21:48
  • Thanks. :) After re-reading, I'm also a little unclear on whether you're after articles, quick tips, or something else? – Peter Boughton Mar 06 '09 at 22:56
  • not sure how to edit.. but: Duplicate() work on CFC instances since CF8. – Henry Mar 07 '09 at 01:20

4 Answers4

1

O'Reilly's Top Ten Tips for Developing ColdFusion Components

kevink
  • 1,938
  • 3
  • 14
  • 14
1

Four quick things:

  1. Get on the CFCDev mailing list (or google groups as it is now).

  2. PDF of a Design Patterns in CFML presentation by Sean Corfield is a good quick read.

  3. http://www.cfdesignpatterns.com has some good stuff with links to quality CFC design articles.

  4. Article on the design patterns in CFML on Rob Brooks-Bilson's Blog .

Todd
  • 522
  • 2
  • 14
  • 33
ethyreal
  • 3,619
  • 2
  • 19
  • 25
0

ColdBox Development Best Practices

Tom Hubbard
  • 15,014
  • 13
  • 56
  • 82
0

Prior to using the ColdBox Framework I did not see any posts about using Momentos to capture the properties at that moment; however, now all my beans have a getMomento() and setMomento() method. I would encourage this as a best practice for anyone who needs to pass information from a bean into a DAO other object.

In my tests, getting a momento is much faster than passing the bean and getting the properties. Here is an example:

<cfcomponent name="userBean" output="true" hint="The account bean holds getter/setter information for a user's account.">

<cfproperty name="idUser"           required="true"     type="string"   rules="noZeroLengthString,validEmail"       invalidMessage="failed_data_validation_email"               hint="Key matching the 'accounts' table.">
<cfproperty name="loginEmail"       required="true"     type="string"   rules="noZeroLengthString,validEmail"       invalidMessage="failed_data_validation_email"               hint="E-mail address.">
<cfproperty name="password"         required="true"     type="string"   rules="noZeroLengthString,validPassword"    invalidMessage="failed_data_validation_password"            hint="Password stored in a SHA-512 hash.">

<cffunction name="init" output="false" returntype="userBean" hint="Initalizes the userBean with default values.">
    <cfset variables.instance               = structNew()>
    <cfset variables.instance.IDUser        = 0>
    <cfset variables.instance.loginEmail    = "">
    <cfset variables.instance.password      = "">
    <cfreturn this>
</cffunction>

<!--- SET LOGIN --->
<cffunction name="setLoginEmail" access="public" returntype="void" output="false">
    <cfargument name="email" type="string" required="true" />
    <cfset variables.instance.loginEmail = trim(arguments.email) />
</cffunction>
<cffunction name="getLoginEmail" access="public" returntype="string" output="false">
    <cfreturn variables.instance.loginEmail />
</cffunction>

<!--- ID --->
<cffunction name="setIDUser" access="public" returntype="void" output="false">
    <cfargument name="id" type="numeric" required="true" />
    <cfset variables.instance.IDUser = arguments.id />
</cffunction>
<cffunction name="getIDUser" access="public" returntype="numeric" output="false">
    <cfreturn variables.instance.IDUser />
</cffunction>

<!--- PASSWORD --->
<cffunction name="setPassword" access="public" returntype="void" output="false">
    <cfargument name="password" type="string" required="true" />
    <cfset var pw = arguments.password>
    <cfif len(pw) EQ 0>
        <cfset variables.instance.password = "">
    <cfelse>
        <!---><cfset variables.instance.password = hash(arguments.password, "SHA-512") />--->
        <cfset variables.instance.password = arguments.password>
    </cfif>
</cffunction>
<cffunction name="getPassword" access="public" returntype="string" output="false">
    <cfreturn variables.instance.password />
</cffunction>

<!--- MOMENTO --->
<cffunction name="setMomento" access="public" returntype="void" output="false">
    <cfargument name="momento" type="struct" required="true" />
    <cfset variables.instance = arguments.momento>
</cffunction>
<cffunction name="getMomento" access="public" returntype="struct" output="false">
    <cfreturn variables.instance />
</cffunction>

Cheers,

Aaron Greenlee My Site

Aaron Greenlee
  • 4,482
  • 4
  • 24
  • 33