About ColdFusion components

About ColdFusion components

A ColdFusion component is a reusable software unit written in ColdFusion markup language (CFML). CFCs help make your code reusable and easy to maintain.

This section describes the advantages of CFCs. Later sections describe how Dreamweaver can help you work with CFCs. For information on CFC tags and syntax, see the ColdFusion documentation from within Dreamweaver (Help > Using ColdFusion).

ColdFusion components are meant to provide a simple yet powerful way for developers to encapsulate elements of their websites. Generally, you should use components for application or business logic. Use customs tags for presentation elements such as customized greetings, dynamic menus, and so on.

As with many other types of construction, dynamic sites can often benefit from interchangeable parts. For example, a dynamic site may run the same query repeatedly, or calculate the total price of shopping cart pages and recalculate it every time an item is added. These tasks can be handled by components. You can fix, improve, extend, and even replace a component with minimal impact to the rest of your application.

Suppose an online store calculates shipping charges based on the price of orders. For orders under $20, the shipping charge is $4; for orders between $20 and $40, the shipping charge is $6, and so on. You could insert the logic for calculating the shipping charge in both the shopping cart page and the checkout page, but that would mix HTML presentation code and CFML logic code and generally make the code difficult to maintain and reuse.

You decide to create a ColdFusion component called Pricing that has, among other things, a function called ShippingCharge. The function takes a price as an argument and returns a shipping charge. For example, if the value of the argument is 32.80, then the function returns 6.

In both the shopping cart page and the checkout page, you insert a special tag to invoke the ShippingCharge function. When the page is requested, the function is invoked and a shipping charge is returned to the page.

Later, the store announces a special promotion: free shipping for all orders above $100. You make the change to the shipping rates in one place--the ShippingCharge function of the Pricing component--and all the pages using the function automatically get accurate shipping charges.

Getting Started with Dreamweaver
Dreamweaver Basics
Working with Dreamweaver Sites
Laying Out Pages
Adding Content to Pages
Working with Page Code
Preparing to Build Dynamic Sites
Making Pages Dynamic
Developing Applications Rapidly
Building ColdFusion Applications Rapidly
Building ASP.NET Applications Rapidly
Building ASP and JSP Applications Rapidly