MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 245

Developing coldfusion mx applications
Table of Contents

Advertisement

The Super keyword lets a component that overrides a base component method execute the
original base component method. This technique lets your subclassed component override a
method without losing the ability to call the original version of the method.
The following sections describe these coding techniques in greater detail.
Using component inheritance
Component inheritance lets you import component methods and properties from one
component into another component. Inherited components share any component methods or
properties that they inherit from other components, and ColdFusion MX initializes instance data
in the parent CFC when you instantiate the CFC that extends it.
When using component inheritance, inheritance should define 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.
When CFC B extends CFC A, CFC A is called the base or parent component; CFC B is called the
the sub or child component.
Note: When you use a component that extends another component, the This scope is not available in
the base (parent) component. Therefore, any component that you extend must not access the
contents of the This scope. However, a component that extends another component, and is not itself
extended, has full access to the This scope.
To use component inheritance:
Open the corpQuery.cfc file, and modify the code so that it appears as follows, or create a new
1
corpQuery.cfc with the following contents:
<cfcomponent extends="appResources.components.tellTime">
<cffunction name="getEmp" returnType="query">
<cfargument name="lastName" required="yes">
<cfquery name="empQuery" datasource="ExampleApps" dbtype="ODBC">
SELECT LASTNAME, FIRSTNAME, EMAIL
FROM tblEmployees
WHERE LASTNAME LIKE '#arguments.lastName#'
</cfquery>
<cfif empQuery.recordcount LT 1>
<cfthrow type="noQueryResult"
message="No results were found. Please try again.">
<cfelse>
<cfreturn empQuery>
</cfif>
</cffunction>
</cfcomponent>
In the example, the
If you do not already have a tellTime.cfc with a
2
following contents, in the same directory as the corpQuery.cfc:
<cfcomponent>
<cffunction name="getLocalTime">
<cfoutput>#TimeFormat(now())#</cfoutput>
</cffunction>
</cfcomponent>
tag's
cfcomponent
extends
attribute points to the
method, create one with the
getLocalTime
Building ColdFusion components
component.
tellTime
245

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents