View comments | RSS feed

CFCs and object-oriented programming

CFCs are building blocks that let you develop ColdFusion code in an object-oriented manner, although CFCs do not require you to do object-oriented programming. Some of the object-oriented features of CFCs include encapsulation, inheritance, and introspection. CFC object-oriented features are similar to the object-oriented elements in other languages, like JavaScript.

The technique of incorporating both code and data into one object such as a CFC is known as encapsulation. Encapsulation lets users pass data to and get a result from your CFC without having to understand the underlying code. When you use encapsulation, you can validate data that is passed to the CFC. CFCs can also enforce data types, check for required parameters, and optionally assign default values.

One CFC can inherit the methods and properties of another CFC. Inheritance lets you build multiple specific components without rewriting the code for the basic building blocks of the components. For more information, see Using inheritance and the Super keyword.

CFCs support introspection; that is, they can provide information about themselves. If you display a component page directly in an HTML browser, inspect it in the ColdFusion and Macromedia Dreamweaver MX component browsers, or use the CFML GetMetadata function, you see information about the component. This information includes its path, property, methods, and additional information that you can specify using special documentation attributes and tags. For more information, see Using introspection to get information about components

When you use a ColdFusion component, you can simply invoke a method in the CFC. However, typically, you create an instance of the CFC, and then invoke methods and refer to properties of the CFC.


ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


JUSTIN OHMS said on Sep 21, 2006 at 3:57 PM :
When calling the functions of a cfc it is important to note the difference between they way java uses the “this” scope and the way coldfusion references it. In Java, a call to this.someMethod() makes the request "inside" the instance. Just as if you had simply called someMethod(). Within a CFC a call to this.someFunction() applies the function call from "outside" the object instance, as if you had instantiated another instance of the class and are now calling the function on it. (Similar to the way the CFINVOKE tag works.) The key problem with this is that if someFunction() is a private function a call to this.someFuntion() will fail as the caller is not in part of the same scope. The solution is to never call a local function from inside of a cfc using “this.” as you might be inclined to if you come from a Java background but instead to call the function directly. e.g. x=someFunction() not x=this.someFunction().

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00001024.htm