I originally gave this presentation at the DFW CFUG in November and December of 2006. This is the first of a series of Mach-II Primers.

Using a traditionally developed application, I will go step-by-step through the process of converting it into an Object-Oriented Mach-II application.

Coldfusion applications have traditionally been developed in a very procedural style. The files of the application generally contain a mix of html, javascript, css, queries and large swatches of conditional business logic - all in the same file. If you're fortunate, common layout elements have been moved into their own files and ed into the content pages.

As new content is required, each page or group of pages is copied and renamed, with the "body" updated as desired.

Often when a "minor" change occurs to one of those included files, to the structure of a database table or the layout of the website as a whole, every file containing that change must be updated. This can lead to drastically increased time in the maintenance of existing code and in the addition of new functionality.

The approach taken by Object Oriented Programming is to create a collection of "objects", where each object manages a certain process and allows other objects to easily connect to, manipulate or extend upon those processes.

Mixing procedural and OO programming can allow for slightly more reusable code, but the application can still be hard to maintain.

Using a programming framework, an application or website can be developed in a manner that can separate business logic, data and the user interface into small, manageable and reusable pieces. Those pieces can then be tied together using a collection of process definitions, stored in a central location.

What is Mach-II?

Mach-II is a programming framework for Coldfusion that integrates the following:

A. A software architecture called Implicit Invocation (the "II" in Mach-II)

Implicit Invocation relies on the concept of an event, rather than the "page" for going from one process to another. For example, the screenshot in Section I shows pages for displaying lists of data, individual records, forms and form data processing. A user can request individual pages regardless of the flow from one page to another.

http://localhost/categories.cfm

Using II, the user does not request the individual files the user requests an event.

http://localhost/index.cfm?event=showCategories

Events can be specified public or private. Public events can be requested directly by the user/browser. Private events can only be called by other events.

B. A design pattern called The Model-View-Controller (MVC)

A design pattern is a defined solution to a recurring issue. The MVC pattern consists of

  1. The Model, which manages data interaction
  2. The View, which manages the User Interface
  3. The Controller, which manages Events by defining the interactions between the Model and the View

C. Object-oriented programming concepts such as Beans, DAOs and Gateways

These concepts will be defined as they are used.

How do I get started?

Install the Mach-II framework. In the /MachII/docs directory. you'll find a Quick Start Guide that will show you how to install the framework onto your Coldfusion server.

Then download the source code for this primer and unzip it into your webroot. The included SQL file will create the tables and data needed for a MySQL database. Scripts for SQL Server and Oracle will be added later, but you should be able to create the tables by looking at .sql file.

The skeleton of the Mach-II Primer groups the files from the procedural application by content in both the Model and Views folders.

For the sake of this primer, files will be versioned under numbered folders that correspond with each Step of the process. This will allow you to see how code is separated bit by bit from procedural, "everything all at once" files into modular, functionality-specific files.

There's a lot to cover at first and we'll be creating many more files than the procedural version has. In the end I hope you'll not only have a better understanding of how Mach-II applications are built, but how frameworks in general can greatly benefit your development efforts.