Building And Using Coldfusion Components - Adobe 38043740 - ColdFusion Standard - Mac Development Manual

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
function Factorial(factor) {
If (factor LTE 1)
return 1;
else
return factor * Factorial(factor -1);
}
If the function is called with a number greater than 1, it calls itself using an argument one less than it received. It
multiplies that result by the original argument, and returns the result. Therefore, the function keeps calling itself until
the factor is reduced to 1. The final recursive call returns 1, and the preceding call returns 2 * 1, and so on, until all the
initial call returns the end result.
Important: If a recursive function calls itself too many times, it causes a stack overflow. Always test any recursive
functions under conditions that are likely to cause the maximum number of recursions to ensure that they do not cause
a stack overflow.

Building and Using ColdFusion Components

A ColdFusion component (CFC) file contains data and functions that you define in related, multiple methods. You
use CFC pages to organize related actions in one file, which provide can simplify your programming. For more
information on creating applications that use CFCs, see the Adobe website: www.adobe.com.
About ColdFusion components
A ColdFusion component (CFC) is a file saved with the extension .cfc. A CFC can contain data and functions. Within
a CFC, data is referred to as properties. Although you use the cffunction tag to define functions within a CFC, they are
typically referred to as methods instead of functions.
The page on which you define a CFC is also known as a component page. Component pages use the same tags and
functions that regular CFML pages do, plus a small number of special tags (in particular, the cfcomponent tag) and tag
attributes.
You define related methods in a CFC. Unlike ColdFusion custom tags, a single CFC can perform many related actions,
defined in multiple methods. The methods can share a data context, such as metadata and scoping, or manage a
particular database or set of tables. For example, you can define the methods to insert, update, delete, and retrieve
records from a particular database or table in one CFC.
CFCs and object-oriented programming
CFCs are building blocks that let you develop ColdFusion code in an object-oriented manner, although CFCs do not
require you to do object-oriented programming. Some of the object-oriented features of CFCs include encapsulation,
inheritance, and introspection. CFC object-oriented features are like the object-oriented elements in other languages,
like JavaScript.
The technique of incorporating both code and data into one object such as a CFC is known as encapsulation.
Encapsulation lets users pass data to and get a result from your CFC without having to understand the underlying
code. When you use encapsulation, you can validate data that is passed to the CFC. CFCs can also enforce data types,
check for required parameters, and optionally assign default values.
One CFC can inherit the methods and properties of another CFC. Inheritance lets you build multiple specific
components without rewriting the code for the basic building blocks of the components. For more information, see
"Using the Super
keyword" on page 202.
Last updated 1/20/2012
177

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents