User Guide

Table Of Contents
Using CFCs effectively 233
3.
Create the president.cfc file with the following content:
<cfcomponent extends="manager">
<cffunction name="getPaid" returntype="numeric">
<cfset var salary=1.5 * Super.getPaid()>
<cfreturn salary>
</cffunction>
</cfcomponent>
4.
Create the payday.cfm file with the following content, and save it in the same directory as the
components that you created in the previous steps:
<cfobject name="empObj" component="employee">
<cfobject name="mgrObj" component="manager">
<cfobject name="prezObj" component="president">
<cfoutput>
<cfoutput>
An employee earns #empObj.getPaid()#.<br>
A manager earns #mgrObj.getPaid()#.<br>
The president earns #prezObj.getPaid()#.
</cfoutput>
</cfoutput>
In this example, each getPaid method in a child component invoked the getPaid method of its
parent component. The childs
getPaid method then used the salary returned by the parents
getPaid method to calculate the appropriate amount.
Included pages can use the Super keyword.
Note: The Super keyword supports only one level of inheritance. If you use multiple levels of
inheritance, you can only use the Super keyword to access the current component’s immediate
parent. The example in this section illustrates handling this limitation by invoking methods in a chain.
Using component packages
Components stored in the same directory are members of a component package. Component
packages help prevent naming conflicts, and facilitate easy component deployment; for example:
ColdFusion searches the current directory first for a CFC. If you put two components in a
single directory as a package, and one component refers to the other with only the component
name, not a qualified path, ColdFusion always searches the package directory first for the
component. As a result, if you structure each applications components into a package, your
applications can use the same component names without sharing the component code.
If you use the access="package" attribute in a method’s cffunction tag, access to the
method is limited to components in the same package. Components in other packages cannot
use this method, even if they specify it with a fully qualified component name. For more
information on access security, see “Using access security” on page 235.