-
Notifications
You must be signed in to change notification settings - Fork 24
Primer Part 1: Introduction
Using a traditionally developed application, I will go step-by-step through the process of converting it into an Object-Oriented Mach-II application.
CFML 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 included 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.
Mach-II is a programming framework for CFML 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://www.example.com/categories.cfm
Using Mach-II, the user does not request the individual files the user requests an event.
http://wwww.example.com/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:
- The Model, which manages data interaction
- The View, which manages the User Interface
- 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.
Install the Mach-II framework. The FAQ shows you how to install the framework onto your CFML server.
Then download the [source code for this primer][mach-ii-primer.zip] 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 the .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.
- Mach-II Primer Series Navigation
- Part 1 - Files versus Events
- Part 2 - Variables versus Arguments
- Part 3 - Flip This Code
- Part 4 - Using Gateways to manage record sets
- Part 5 - Mediating events with Listeners
- Part 6 - Getting the details with Beans and DAOs
- Part 7 - Processing data with Beans and DAOs using Event-Filters
Special thanks to Adrian J. Moreno of IKnowKungFoo for contributing this series of primers.