Cold-Foo
Release: b1
2002-02-17 12:45
Installation
You must have access to create ColdFusion Mappings in the ColdFusion Administrator. CFREGISTRY and CFFILE must also be enabled.
1. Copy/Move the "/Place In CustomTags/CFOO" directory into your CustomTags directory. Example: C:\CFUSION\CustomTags\CFOO\
2. Move the Example application folder into your web-server's htdocs some where.
3. You'll also need to create a ColdFusion Mapping using the CF Administrator. Create a mapping called "Objects" and point it to the Objects folder in the Example application folder.
Packages
Every class belongs to a package. For class "Objects.ExampleClass" it's package is "Objects". For each top-level package name, there must be a CF Mapping for it. These values are also passed when calling <cf_cfooAppInit>. A class is contained in a folder inside the package's folder.
You can create sub-package names, as well. Example: Objects.common.class1, Objects.common.class2, etc. If you create another package, say "ShoppingCart", you would have classes within that folder. "ShoppingCart.Customer", "ShoppingCart.Cart", and so on. You'd then have to make a CF Mapping named "/ShoppingCart" and map it to the top ShoppingCart folder.
ClassBuilder
The ClassBuilder is a utility to help you define a Class, it's parent classes (if any), its fields, and it's methods. The ClassBuilder automatically creates the _classDef.wddx file inside the Class's folder. The CFOO Framework requires a proper classDef file to work correctly.
To do:
Create ClassBuilder publishing templates for:
-- class files, method stubs, auto-accessors
-- sql scripts to create/alter tables
-- stored procedures
-- auto-documentation
-- unit-tests
Creating a Class
Specify a name of the class, including it's packages. For example:
Objects.ExampleObject
The class is "ExampleObject", and it's inside the package "Objects". Make sure you have a CF Mapping for the top-level package name, or the ClassBuilder and the rest of the framework will die.
Using the ClassBuilder, type in the name of your Class. The folders up to the Class will be created, along with the Class file itse'f, ExampleObject.cfm for example. And the _classDef.wddx file will also be created.
Use the ClassBuilder to add fields/methods. This doesn't generate any code, at this point, make sure you actually implement your fields and methods :)
Instantiating an Object
Use the <cf_new> tag to instanciate a new instance. Example:
<cf_new class="Objects.ExampleObject" object="myObj">
This will create a new instance, execute it's class file (ExampleObject.cfm), and return the resulting instance into a variable called "myObj".
Calling a Method on an Instance
You have two ways of executing a method on an instance, since there are two types of methods. UDFs and Tag-based methods.
Tag-Based methods are actual CF files inside the Class folder. Their filename is the method name. You call these kinds of methods with the <cf_method> tag. Example:
<cf_new class="Objects.ExampleObject" object="myObj">
<cf_method object="#myObj#" method="getName" [variable="result"]>
The variable attribute is optional. It defaults to setting "result" to whatever the method returned.
RULE: All method implimentations should set caller.result to their result value. The <cf_method> tag takes care of placing the value in the correct variable name.
UDF Methods are called without any Custom Tag involved. Example:
<cfscript>
myName = myObj.getName(myObj);
</cfscript>
Notice you MUST pass in the OBJECT to it's own method. This is hokey, I know, but there's no other way to do it.