
ColdFusion MX 7 Getting Started Experience Tutorial Page 42 of 47
Figure 59. Selecting a new
ColdFusion component
document
Learning Point: ColdFusion components
One of the best practices of programming is a requirement to separate business processes from display elements.
Currently, the index.cfm page contains both a query and the HTML to display the data. To adhere to the best practice
mentioned previously, you should separate the two. You use a ColdFusion component (CFC) to do this by having it
contain the query.
In general, CFCs are a collection of business processes for an application. Usually, these processes are organized into
logical units. For instance, a shopping cart application might have multiple CFCs: shoppingCart.cfc, products.cfc,
orders.cfc, customers.cfc, and so on. Each CFC contains functions. For instance, the shoppingCart.cfc might have
addToCart, removeFromCart, totalCart, and other functions, while the products.cfc might have functions like addProduct,
editProduct, and deleteProduct.
Separating all the processes into discrete units, as well as separating the business processes from display elements,
makes it much easier to reuse your code.
2. Notice that Dreamweaver created an untitled page with some initial template code on it, as the following figure shows.
Save the page and name it art.cfc.
<cfcomponent>
<cffunction name="myFunction" access="public" returntype="string">
<cfargument name="myArgument" type="string" required="true">
<cfset myResult="foo">
<cfreturn myResult>
</cffunction>
</cfcomponent>
Kommentare zu diesen Handbüchern