User Guide

Table Of Contents
232 Chapter 10: Building and Using ColdFusion Components
When you browse the inherit.cfm file, the manager component refers to the basesalary defined
in employee.cfc, which is the base component; the
president component refers to both the
basesalary defined in the employee component, and the mgrBonus defined in the manager
component. The
manager component is the parent class of the president component.
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: If you install a newer version of ColdFusion, the installation procedure replaces the existing
component.cfc file with a new version. Therefore, before upgrading to a new version of ColdFusion,
you should 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 Extends attribute to extend another CFC.
Unlike ColdFusion 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
getPaid method. The manager CFC extends the employee CFC. Therefore, the
manager CFC can use the original versions of the overridden
getPaid method, as defined in the
employee CFC, by prefixing the method name with Super.
To use the Super keyword:
1.
Create the employee.cfc file with the following content:
<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>