Over the past few years there has been a move within the ColdFusion community towards structured and/or object oriented approaches to application development. Using modern techniques you can separate your applications into “tiers”. For instance, you might create a set of components which are responsible for your application’s database access, another set for the application’s business logic and yet another to display output.
These techniques have given birth to multiple frameworks which aid development. Examples of these for ColdFusion are Model-Glue, Mach-II and Fusebox.
However, as the industry moves towards an object oriented approach to database access; many developers find that simply moving queries into components does not provide the flexibility and power they expected.
For this reason several design patterns have evolved which can help programmers find consistent and flexible solutions to these problems. These design patterns include:
Data Access Objects – Data Access Objects (commonly called DAOs) are objects which provide methods for creating, reading, updating and deleting a single record in a database. These are generically known as “CRUD” methods.
Table Data Gateways – Table Data Gateway objects (commonly known as Gateway Objects) are used to interact with multiple rows in a database. Most methods in these objects return record sets (queries) and perform select statements.
Active Records – The Active Record design pattern is new to many developers but has become familiar due to well recognized and respected implementations including the Ruby on Rails framework. There are many flavors of this design pattern. Most implementations are of one object which represents one row in a database. The object has assessors and mutators (methods for getting and setting values) as well as methods for reading a record, saving it, and deleting it. There are also frequently methods for accessing related objects in the database.
Frequently, other common types of objects are also used which serve the purposes of moving data around, validating data and more.