Adobe COLDFUSION 9 Manual page 207

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
4
Create the inherit.cfm file with the following content, and save it in the same directory as the components you
created in the previous steps:
<cfobject name="empObj" component="employee">
<cfobject name="mgrObj" component="manager">
<cfobject name="prezObj" component="president">
<cfoutput>
An employee's salary is #empObj.basesalary# per week.<br>
A manager's salary is #mgrObj.basesalary + mgrObj.mgrBonus# per week.<br>
A president's salary is #prezObj.basesalary + prezObj.mgrBonus +
prezObj.PrezBonus# per week.
</cfoutput>
When you browse the inherit.cfm file, the
which is the base component; the
component, and the
mgrBonus
component.
president
Using the component.cfc file
All CFCs automatically extend the ColdFusion WEB-INF/cftags/component.cfc component. (The WEB-INF
directory is in the cf_root/wwwroot directory on ColdFusion configured with an embedded J2EE server. It is in the
cf_root directory when you deploy ColdFusion on a J2EE server.) This CFC is distributed as a zero-length file. You can
use it for any core methods or properties that you want all CFCs in your ColdFusion application server instance to
inherit.
Note: When you install a newer version of ColdFusion, the installation procedure replaces the existing component.cfc file
with a new version. Therefore, before upgrading, save any code that you have added to the component.cfc file, and then
copy the code into the new component.cfc file.
Using the Super keyword
You use the Super keyword only on CFCs that use the
scopes, the Super keyword is not used for variables; it is only used for CFC methods, and it is not available on
ColdFusion pages that invoke CFCs.
The Super keyword lets you refer to versions of methods that are defined in the CFC that the current component
extends. For example, the employee, manager, and president CFCs each contain a
extends the employee CFC. Therefore, the manager CFC can use the original versions of the overridden
method, as defined in the employee CFC, by prefixing the method name with Super.
Create the employee.cfc file with the following content:
1
<cfcomponent>
<cffunction name="getPaid" returntype="numeric">
<cfset var salary=40*20>
<cfreturn salary>
</cffunction>
</cfcomponent>
2
Create the manager.cfc file with the following content:
<cfcomponent extends="employee">
<cffunction name="getPaid" returntype="numeric">
<cfset var salary=1.5 * Super.getPaid()>
<cfreturn salary>
</cffunction>
</cfcomponent>
component refers to the
manager
component refers to both the
president
defined in the
component. The
manager
Extends
Last updated 8/5/2010
defined in employee.cfc,
basesalary
defined in the
basesalary
component is the parent class of the
manager
attribute to extend another CFC. Unlike ColdFusion
method. The manager CFC
getPaid
202
employee
getPaid

Advertisement

Table of Contents
loading

Table of Contents