Structures
CF structures are very similar to JavaScript structures, in that they can be declared as follows using object-literal notation:
var myStruct = {key: "value1", key2: "value2"};
Structure members can then be accessed like this:
var myValue = myStruct.key; /* "dot" notation */
var myValue = myStruct["key"]; /* "array" notation */
var myKey = "key";
var myValue = myStruct[myKey]; /* indirection through "myKey" variable */
Much like MUMPS, CF structures can pop into existence simply by having values assigned to them:
var myStruct["key1"]["key2"] = "value"; /* this is just like SET myStruct("key1","key2")="value" in MUMPS */
We can test for the existence of a key like this:
if(structKeyExists(myStruct, "key")) {
writeOutput("The key 'key' exists in 'myStruct'!");
}
The primary difference between CF structures and MUMPS trees is that CF structures are not automatically sorted into any particular collating order: because CF structures are internally implemented as hashes, keys are stored in the order in which they are inserted.
ColdFusion Components
The CFML programming language provides object-oriented programming facilities by way of CF Components, commonly referred to as CFCs. Each CFC is conceptually similar to a class in other OO languages, which means that a CFC encapsulates both data and code. Data members of CFCs are referred to as properties, while the code to interact with those properties are methods. All CFC methods are actually functions (similar to extrinsic functions in MUMPS) which gain the benefits of the properties exposed in their containing CFC. In the case of CFMumps, each API is a CFC whose properties define and maintain the state of the MUMPS database connection, and whose methods are the APIs against which your applications will be developed, such as get(), set(), kill(), data(), and order().
You can think of each CFC as a complex, high-level data type that just happens to also contain code that you can run.
In order to gain access to the methods and properties of the CFCs which implement the CFMumps API, you need to create an instance of the appropriate CFC. An instance is simply a variable through which you access the methods and properties of the API you wish to use. Creating an instance is accomplished with the createObject() CFML/CFScript function.
Here is an example–expressed in both CFScript and tag-based CFML--creating an instance of the basic API:
var myCFCInstance = createObject("component", "lib.cfmumps.mumps");
<cfset var myCFCInstance = createObject("component", "lib.cfmumps.mumps")>
Each of the above code snippets will produce identical results: the variable myCFCInstance is created and initialized as an instance of lib.cfmumps.mumps, which is the component that implements the CFMumps basic API. Its methods are available by appending a dot to the variable name myCFCInstance, followed by the name of the method you wish to call, as follows:
<cfset myCFCInstance.open()>
The above examples open the database for the myCFCInstance instance of the lib.cfmumps.mumps CFC.
Add Comment