Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 206

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Using CFCs effectively
Several techniques let you effectively use CFCs in your applications:
• Structure and reuse code
• Build secure CFCs
• Use introspection to get information about components
Structuring and reusing code
Component inheritance and the Super keyword are two important tools for creating structured, object-oriented
ColdFusion components.
Lets you create a single base component and reuse this code in multiple subclasses that are
Component inheritance
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.
Lets a component that overrides a base component method execute the original base component
The Super keyword
method. This technique lets your subclassed component override a method without losing the ability to call the
original version of the method.
Using component inheritance
Component inheritance lets you import component methods and properties from one component to another
component. Inherited components share any component methods or properties that they inherit from other
components, and ColdFusion initializes instance data in the parent CFC when you instantiate the CFC that extends it.
Component inheritance defines an is a relationship between components. For example, a component named
president.cfc inherits its methods and properties from manager.cfc, which inherits its methods and properties from
employee.cfc. In other words, president.cfc is a manager.cfc; manager.cfc is an employee.cfc; and president.cfc is an
employee.cfc.
In this example, employee.cfc is the base component; it's the component upon which the others are based. The
manager component extends the employee component; it has all the methods and properties of the employee
component, and some additional ones. The president component extends the manager component. The president
component is called a subcomponent or child component of the manager component, which, in turn, is a child
component of the employee component.
Create the employee.cfc file with the following content:
1
<cfcomponent>
<cfset This.basesalary=40*20>
</cfcomponent>
2
Create the manager.cfc file with the following content:
<cfcomponent extends="employee">
<cfset This.mgrBonus=40*10>
</cfcomponent>
In the example, the cfcomponent tag's
Create the president.cfc file with the following content:
3
<cfcomponent extends="manager">
<cfset This.prezBonus=40*20>
</cfcomponent>
In the example, the cfcomponent tag's
attribute points to the
extends
attribute points to the
extends
Last updated 1/20/2012
component.
employee
component.
manager
201

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents