Mach II or ColdSpring? Understanding the Differences Between ColdFusion Frameworks
I am paraphrasing here, but this is a type of question I have seen from time to time posed on lists, blogs and elsewhere. In part this has to do with a generic use of the term "framework" to apply to a lot of different projects that solve entirely different problems. You could, for instance, build an application that uses Mach II, Transfer and ColdSpring, thereby using three (or more) frameworks in a single application and this would be totally appropriate. Why? Well because Mach II is concerned, in very general terms, with your overall architectual pattern, Transfer with your persistence mechanism and ColdSpring with managing dependencies within your model. Confused? Well, here is a guide to the most commonly referred to types of frameworks, the problems they attempt to solve and the well-known ColdFusion frameworks associated with that type.Writer's Note: First, if you find factual/conceptual errors or inconsistencies, please see my note at the end of this post. Second, while all kinds of frameworks in ColdFusion can be a hot button issue, this post was written in an attempt to present the topic in a more general and objective manner primarily for beginners. There are no digs in here, and if you find one, its because you are looking for them (and your determination is coloring your reading). So I welcome constructive criticism but, please, no flames.
Model-View-Controller (MVC)
This is the largest category of ColdFusion frameworks and includes many projects with a wide-range of features but that, at their core, solve the same architectural problem. That problem would be how to protect your user interface (UI) from having to know about changes to your model, which basically represents your data, and vice-versa.
MVC does not have to be object-oriented (OO). In fact, the first MVC framework for ColdFusion, Fusebox was decidedly not OO in its early years (nowadays it can be used procedurally or with objects). Mach II was spun off of Fusebox and, in its first early beta phases, was originally called Fusebox MX. Mach II took a more object-oriented approach towards MVC with the advent of CFCs in ColdFusion MX. Both of these frameworks have been around for quite some time and are widely used throughout the ColdFusion community.
Model-Glue, another more recent ColdFusion MVC framework, has gained a strong following lately in part by simplifying how various events were called via the configuration XML (and theoretically being easier on someone new to object-oriented concepts). Although not yet in a stable release, Model-Glue 2.0 (called Unity) has diverged further from the Mach II mold by including a number of features like scaffolding and object-relational mapping (discussed later) normally associated with the Ruby on Rails MVC framework for the Ruby programming language.
While these frameworks make up the "big three" of ColdFusion (as some refer to them), they are by no means the only ones, though most of the others are relatively new. Some of the others include the ColdBox Framework, ColdFusion on Wheels and CFRails, to name only a few of the more well known.
Inversion of Control (IoC) or Dependency Injection
The two terms used to describe the next set of frameworks seem to be used interchangeably. Basically IoC is a means of simplifying object dependencies (in this case obviously we mean ColdFusion components), and is therefore specifically related to object-oriented programming.
In a typical application, object dependencies are handled through a series of hard-coded calls to the dependent objects within a component, perhaps in the constuctor (init()) method (i.e. a series of CreateObject() calls in CFML). While this is functional, it can become difficult to maintain within large models that have a lot of dependencies and would require a large amount of recoding for something as simple as a component moving within the model's folder structure.
IoC solves this problem by "injecting" the dependencies into the objects when they are created, thereby relieving your object/component from having to know the specifics of where the dependency is coming from or how it is created. Most IoC frameworks can also handle circular (or cyclic) dependencies, whereby two objects are dependent on each other.
The standard for doing IoC in ColdFusion is ColdSpring, which is based in-part on Java's Spring framework and also includes an aspect-oriented programming (AOP) portion which we will discuss next. LightWire is a relatively new addition to IoC in ColdFusion, though it is still in its early stages of development.
Aspect-Oriented Programming (AOP)
Potentially the most difficult concept for beginners to understand, AOP deals with "cross-cutting concerns" (i.e. aspects) within your application. These are things like security or logging that apply to large portions of your application and are not really "objects". In fact, AOP as a concept does not necessarily apply specifically object-oriented development, though I have not personally seen it done any other way.
AOP solves the problem of integrating these cross cutting concerns by creating "join points" (referred to as pointcuts) and "advice." The join point or pointcut is the place within a program where the advice will be applied. For example, we might want to set our logging to occur before, after or around certain method calls. The advice would be what we want to happen at this join point (i.e. a method call or sequence of method calls). In our logging application, for example, the advice would be the actual implementation of the logging code.
Currently, the only framework (that I am aware of) to implement AOP for ColdFusion is ColdSpring.
Object Relational Mapping (ORM)
Many people associate object-relational mapping with CRUD (i.e. your standard create, read, update and delete code for any item in your model). While ORM does handle CRUD, there are many solutions to CRUD that are not ORM (for example, in ColdFusion, DataMgr solves CRUD in manner that is more procedural in nature). The difference is that ORM deals with a specific problem, and that is when your application's model deals in objects, but your persistence method (i.e your database) is relational. While the average person sees ORM as a way not to write queries anymore, the problem is far more complex than that (a code generator for example can solve the problem of writing queries but is not ORM).
A standard ORM solution contains a means of "mapping" object data to relational data. This means, in large part, that relationships like your "has a", "has many" or "is a" are converted to "flat" relationships using keys. Obviously your ORM also handles persisting object properties, like the "firstName" in my user object, in its proper table location in my database. While the basic problem may sound simple, ORMs have to deal with a multitude of complexities such as an single object that spans multiple relational tables or deep, nested relationships in addition to accomodating the SQL language differences between the various supported RDBMS.
While Hibernate has become a de facto standard it seems in the Java world, ColdFusion has several well known ORM projects. One of the first ORM projects in ColdFusion was Transfer, which based upon my limited experience, takes a more Hibernate-ish approach to ORM in which a Transfer "business object" is similar in many respects to Hibernate's persistance of POJOs (i.e. Plain Old Java Objects).
Another widely used and well-known ORM for ColdFusion is Reactor. Reactor's approach to ORM is quite different than Transfer, bearing more similarity to the "Active Record" pattern popularized by Ruby on Rails. Reactor also includes a full-blown object-oriented query language that theoretically eliminates the need for any portion of your model to be aware of which RDBMS it uses.
Another widely used ORM in ColdFusion is ObjectBreeze, which differentiates itself from the above two in that it doesn't require any configuration (like an XML file), but creates objects via its API at runtime.
In addition, some of the MVC frameworks listed in the above section contain some level of ORM. Model-Glue, for example, includes Transfer and Reactor integration aspects. Other "Rails-like" frameworks such as ColdFusion on Wheels and CFRails typically include some level of ORM.
Conclusion
Obviously these are not the only types of frameworks that exist either in the programming world in general or in ColdFusion specifically. However, when you hear people make the generic "framework" reference, they are usually referring to one of these four types. I think that, having covered the different types of problems they solve can help to alleviate the confusion this often causes those of us just entering the relatively new world of frameworks in ColdFusion. Now, you too will be confused when you hear someone wondering if they should use Mach II or ColdSpring.
One important note: I am by no means an expert on all of these topics or frameworks, so, if you find a concept that was wrongly explained, a term that was misused or an incorrect description of the features, requirements or approach of the frameworks discussed, please put this in the comments and I will try to take this into account and make the necessary corrections. Thanks to Wikipedia for all the reference material :)
