Listing 1
<!--- user_list.cfm
A Controller Page --->

<cfset request.data=createobject("component", "user_db")>
<cfif isdefined("url.sort")>
<cfset request.data.setSortOrder(url.sort)>
</cfif>
<cfinclude template="user_list_view.cfm">

Listing 2
<!--- A Data Provider component 
This is a "child" CFC which inherits
most of its functionality from its
"super", dbmodel.

All variables with "this" prefix are
initialized in the super CFC.
--->

<cfcomponent extends="dbmodel" output="false">
<cffunction name="init" output="false"
access="public">
<cftry>

<!--- Query the database --->
<cfquery name="this.query" datasource="#this.dsn#">
SELECT * from users
<cfif this.sortorder neq "">
ORDER BY #this.sortorder#
</cfif>
</cfquery>
<cfcatch>
<!--- If the query fails, create a dummy query --->
<cfinclude template="user_dummyquery.cfm">
</cfcatch>

</cftry>
</cffunction>
</cfcomponent>

Listing 3
<!--- A "super" CFC, which is extended
by CFCs bound to particular DB tables --->

<cfcomponent displayname="Data Model Super CFC" 
output="false">
<!--- Constructor code - initialize variables
upon instantiation of the data object --->
<cfset this.currentrow=1>
<cfset this.query="">
<cfset this.sortorder="">
<cfset this.dsn="MyDSN">

<!--- Set the query sort order --->
<cffunction name="setSortOrder" 
output="false" access="public">
<cfargument name="sortorder" required="yes" 
type="string">
<cfset this.sortorder=arguments.sortorder>
<cfset this.query="">
</cffunction>

<!--- Advances "cursor" to next record if possible,
returns false if it's already there --->
<cffunction name="next" returntype="boolean"
access="public" output="false">
<cfif not isquery(this.query)>
<cfset this.init()>
<cfset this.currentrow=1>
<cfreturn true>
<cfelseif this.currentrow eq 
this.query.recordcount>
<cfreturn false>
<cfelse>
<cfset this.currentrow=this.currentrow+1>
<cfreturn true>
</cfif>
</cffunction>

<!--- Returns the value of a particular field 
in the current row of the current table --->
<cffunction name="getValue" access="public"
output="false">
<cfargument name="fieldname" 
required="true" type="string">
<cfif not isquery(this.query)>
<cfset this.init()>
</cfif>
<cfreturn 
this.query[arguments.fieldname][this.currentrow]>
</cffunction>

<!--- Return current row number --->
<cffunction name="getCurrentRow" returntype="numeric"
access="public" output="false">
<cfreturn this.currentrow>
</cffunction>

</cfcomponent>

Listing 4
<!--- user_list.cfm
A View of a user list
Depends on a data object being present in
the request scope
--->
<cfset data=request.data>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>User Information</title></head>
<body>

<table border="1">
<tr bgcolor="#FF66FF">
<!--- In MVC terminology, these hyperlinks are 
messages sent from the View to the Controller --->
<cfoutput>
<th>
<a href="#cgi.script_name#?sort=user_name">Name</a>
</th>
<th>
<a href="#cgi.script_name#?sort=user_city">City</a>
</th>
</cfoutput>
</tr>
<cfloop condition="data.next()">
<!--- A Nested View --->
<cf_view_row fieldlist="user_name,user_city">
</cfloop>
</table>

</body></html>

Listing 5
<!--- view_row.cfm Custom Tag
required attribute: fieldlist 
(comma-delimited list of fields)
--->
<cfset data=request.data>
<cfif (data.getCurrentRow() mod 2)>
<cfset bgcolor="white">
<cfelse>
<cfset bgcolor="silver">
</cfif>
<cfoutput>
<tr bgcolor="#bgcolor#">
<cfloop list="#attributes.fieldlist#"
index="fieldname">
<td>#data.getValue(fieldname)#</td>
</cfloop>
</tr>
</cfoutput>

Listing 6
<!--- user_dummyquery.cfm 
Creates a query object for testing 
when the database isn't available
--->
<cfscript>
this.query=QueryNew("user_name, user_city");
queryAddRow(this.query);
querySetCell(this.query, "user_name", "David");
querySetCell(this.query, "user_city", "Napa");
queryAddRow(this.query);
querySetCell(this.query, "user_name", "Mary");
querySetCell(this.query, "user_city", "San Francisco");
queryAddRow(this.query);
querySetCell(this.query, "user_name", "Alex");
querySetCell(this.query, "user_city", "San Jose");
queryAddRow(this.query);
querySetCell(this.query, "user_name", "Lisa");
querySetCell(this.query, "user_city", "Los Angeles");
</cfscript>

<cfif this.sortorder neq "">
<cfquery name="this.query" dbtype="query">
SELECT * from this.query ORDER BY #this.sortorder#
</cfquery>
</cfif>