Cfc best practices tips and tricks
Download
1 / 13

CFC Best Practices, Tips, and Tricks - PowerPoint PPT Presentation


  • 134 Views
  • Updated On :

CFC Best Practices, Tips, and Tricks. Raymond Camden [email protected] Agenda. Basic (but real!) Examples Best Practices (Suggestions) Tips and Tricks Resources. Examples. www.cflib.org CFCs serve as DB abstraction ResourceBundle CFC Localization Utility SimpleCMS

Related searches for CFC Best Practices, Tips, and Tricks

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CFC Best Practices, Tips, and Tricks' - constance


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Agenda
Agenda

  • Basic (but real!) Examples

  • Best Practices (Suggestions)

  • Tips and Tricks

  • Resources


Examples
Examples

  • www.cflib.org

    • CFCs serve as DB abstraction

  • ResourceBundle CFC

    • Localization Utility

  • SimpleCMS

    • Simple CMS based on CFCs


Best practices
Best Practices

  • Control white space generated by CFC

<cfcomponent displayName="Example" output="false">

<cffunction name="test" returnType="string" access="public" output="false">

<cfreturn "This is a boring function.">

</cffunction>

</cfcomponent>


Best practices1
Best Practices

  • Supply Optional Attributes

<cfcomponent displayName="Example2" output="false">

<cffunction name="test" returnType="string" access="public" output="false"

hint="This function does blah using Foo's logic.">

<cfargument name="argone" type="string" required="true">

<cfargument name="argtwo" type="numeric" required="false" default="0">

<cfreturn arguments.argone & " with the number " & arguments.argtwo>

</cffunction>

</cfcomponent>


Best practices2
Best Practices

  • Use the VAR scope!

<cfcomponent displayName="Example3" output="false">

<cffunction name="test" returnType="string" access="public" output="false">

<cfargument name="argone" type="string" required="true">

<cfset var i = 0>

<cfloop index="i" from=1 to=10>

.....

</cfloop>

</cffunction>

</cfcomponent>


Understand data scopes
Understand Data Scopes

  • Variables

  • This

  • Arguments

  • Function Local


Cache cfc instances
Cache CFC Instances

  • CFC creation can be slow.

  • Use createObject/cfobject to create an instance.

  • <cfinvoke> (typically) works with new instances.


Pseudo constructor
Pseudo-Constructor

  • Any code not inside <cffunction>.

  • Useful to initialize variables.

  • BlueDragon has <cfconstructor>


Dealing with application variables
Dealing with Application Variables

  • Application.cfm and when it's run:

    • Flash Remoting/WS calls

    • Same folder

  • Don't rely on it!

  • Application CFC


Inheritance super
Inheritance/Super

  • Use for Is-A, not Has-A

    • In other words, inheritance is used when a CFC defines as "is a" relationship with it's parent. It should not be used for simple code re-use.

  • Super allows for a child method to extend a parent method.


Pass by ref by value
Pass by Ref/by Value

  • Values passed to CFC methods follow the same rules as values passed to UDFs.

  • The following are passed by reference:

    • Structures

    • Queries

    • Other "comlpex" objects (including CFCs)


Resources
Resources

  • www.cfczone.org

  • cfcdev mailing list

  • Top Ten Tips article by Rob Brooks-Bilson

    • http://www.oreillynet.com/pub/a/javascript/2003/09/24/coldfusion_tips.html?page=1

  • CFC Best Practices by Nathan Dintenfass

    • http://www.dintenfass.com/cfcbestpractices/


ad