ColdFusion Markup Language - ColdFusion Components (CFCs)

ColdFusion Components (CFCs)

CFCs provide some (not all) of the typical features and functionality that are provided by object-oriented (OOP) languages. To create a CFC:

Create a file with a .CFC extension (this distinguishes CFCs from ColdFusion templates, which have a .CFM extension).
Use four tags to create the components, define their functions and arguments, and return a value.
: Defines a CFC
: Defines the functions (methods) within a CFC
: Defines the arguments (parameters) that a function accepts
: Returns a value or result from a function

CFCs are plain CFML. Within a CFC any CFML tag, function, custom tag, other components, etc. may be used.

CFCs can be used in various ways. If a method contained in a CFC simply needs to be invoked, the tag will create an instance of the CFC, invoke the desired method, and then destroy the instance of the CFC. takes the name of the component (minus the .cfc extension) and the method to execute. To access any returned data, the RETURNVARIABLE attribute provides the name of a variable to contain whatever the function returns. CFCs are created using four tags, saved as .CFC files, and invoked using the tag.

In the example below, component temperature.cfc has a method FtoC which converts temperature from Fahrenheit to Celsius. The test.cfm template invokes the method and converts 212 degrees Fahrenheit and outputs the result.

#fDegrees#°F = #result#°C

CFCs may also be instantiated as objects. Assuming a CFC file called Person.cfc, an instance of this CFC would be instantiated as follows:

CFCs also form the basis of the ability to create web services in CFML. A CFC is created in the usual way, and the attribute access="remote" added to any function within the CFC will make that function available to be called as a SOAP-based web service. The CFML engine auto-generates a WSDL and creates all the necessary stubs for the web service to function.

Read more about this topic:  ColdFusion Markup Language

Famous quotes containing the word components:

    Hence, a generative grammar must be a system of rules that can iterate to generate an indefinitely large number of structures. This system of rules can be analyzed into the three major components of a generative grammar: the syntactic, phonological, and semantic components.
    Noam Chomsky (b. 1928)