What is Scaffolding and how do I use it? - Part 1

You need scaffolding!

So you read something somewhere that said you should be using scaffolding and want to know how? Let me tell you a story.

ColdFusion has been developed to make creating applications easier right?

It certainly seemed that way when I downloaded it first. It was way easier that anything else available at the time. I first found out about it from a guy in bar. I was in San Francisco for the Web Innovations conference in December 1995. I told him what my customer wanted and how I was an expert in Visual Basic and was going to make web pages with it. He looked at me like with sorrow as slipped the paper with a single URL (www.allaire.com) into my hand. "You'll need some help!" he said.

I rapidly developed pages in CFML and they worked quickly and did a good job, but over time my applications got more complex and the pages more difficult to design. In fact I wasn't making pages anymore. I was making applications and they needed architecture. About that time Fusebox came to the rescue and that was great for a while, but them my applications got more complex. Then Fusebox evolved and grew and solved my problems. It even solved problems I didn't even know I had!

After a while CFMX came along and offered new features and a whole new world of OO was beckoning. That didn't seem to relate to my old fusebox world.

Then design patterns came and showed the way with DAO, Gateway and Services integrating into my old friend fusebox. Everyone told me this was best practice and after a lot of hard work the evidence was there. Applications really were easy to maintain. One of my customers changed their database overnight from the old one designed by me to a new one designed to accommodate a CRM system, but the architecture proved its worth. The changes were made on time and within budget.

While the new architecture is great for large applications it does seem difficult to get started. For a start there is lots of typing. I hate typing! Its boring typing. All those DAO s and Gateways and Services and Beans have to be built. The days of rapid development seem a long time ago.

Sometimes I long for that time long ago and those simple applications that didn't need an architecture. Occasionally I get tempted. It always turns out to be a mistake to give in. After a few days, one page has grown to ten, after a month it's running on three machines and has web services linking it to servers on three continents! I wake up at night screaming, dreaming, of the nightmare email asking for one small change to the simple, one page, application.

Scaffolder to the rescue.

The fusebox scaffolder is a code generator. It reads my database and creates code based on metadata in the database and some templates. I don't have to write the DAO and Gateway and Service and Bean any more. I create an index.cfm file and copy the 4 lines of scaffolder initialization code and the fusebox code into it. I change the datasource name to point at the database that is waiting for me and fire up the browser and wait. After a couple of minutes the application starts. All my code is there! A directory full of DAOs and Gateways and Services and Beans! No typing!

I am happy again. My customer is happy again. My nightmares are gone. Am I dreaming? When will I wake up? More to follow....

Comments
Greg Stevens's Gravatar Have been getting more into CFCs and proper OO methodologies lately, 90% of it is all making sense and every day more and more becomes clear, however one thing that has been bugging me lately is the difference between a Gateway CFC and a Service CFC. In my mind a Gateway CFC deals with the database when retrieving more then 1 record. I mainly deal with Beans which extend a DAO, which just simplifies things so that I can take an active record approach of going with something like user.saveRecord() and have it perform the proper DB calls. I should be using ColdSpring and injecting the DAO into the bean so that only 1 instance of the DAO exists at any time, but I just haven't quite made the time to do that yet. I'm tarting to get offtrack, sorry. My question is - I find I need to have a CFC that co-ordinates actions between multiple beans, takes some sort of action, performs business logic on 2 different entity beans.etc. I am wondering - would this be considered a Service CFC? A Manager CFC? Something else?

What kind of functions does the Fusebox Scaffolder put into the Service CFCs it generates?

Thanks!

p.s. - going to post this to the CFCDev mailing list as well just to have it on record there.
# Posted By Greg Stevens | 9/30/07 9:03 PM
Kevin Roche's Gravatar Yes this is a job for Service CFC. There are actually two different scaffolder templates in the Alpha. The ColdSpring template currently creates a DAO, Gateway, Record, Transfer Object and a Service. There are instructions in the Docs on how to add more. I am hoping people will submit their own templates too.
# Posted By Kevin Roche | 10/2/07 11:19 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.