User Guide

Table Of Contents
230 Chapter 10: Building and Using ColdFusion Components
Tip: You should always use the Var keyword on variables that are only used inside of the function in
which they are declared.
You must define all function local variables at the top of the function definition, before any other
CFML code; for example:
<cffunction ...>
<cfset Var testVariable = "this is a local variable">
<!--- Function code goes here. --->
<cfreturn myresult>
</cffunction>
Any arguments declared with the cfargument tag must appear before any variables defined with
the
cfset tag. You can also put any cfscript tag first and define variables that you declare with
the Var keyword in the script.
Use function local variables if you put the CFC in a persistent scope such as the Session scope,
and the function has data that must be freed when the function exits.
Local variables do not persist between calls to CFC methods.
Local variables are available to pages included by the method.
Using CFCs effectively
This section describes the following techniques:
Structuring and reusing code
Building secure ColdFusion components
Using introspection to get information about components
Structuring and reusing code
The following sections provide information about the techniques that ColdFusion MX provides
for structuring and reusing component code:
Using inheritance and the Super keyword
Using component packages
Using CFCs in persistent scopes
Using inheritance and the Super keyword
Component inheritance and the Super keyword are two important tools for creating structured,
object-oriented ColdFusion components.
Component inheritance lets you create a single base component and reuse this code in multiple
subclasses that are derived from the base component. Typically a base component is more general,
and subcomponents are typically more specific. Each subclass does not have to redefine the code
in the base component, but can override it if necessary.
The Super keyword lets a component that overrides a base component method execute the
original base component method. This technique lets your subclassed component override a
method without losing the ability to call the original version of the method.