Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Tiers, Not Tears
Tiers, Not Tears

At last year's Developer's Confer-ence I presented a session on creating n-tier (or multitier) applications in ColdFusion, explaining how tiered applications were more manageable and reusable. So why bring this up almost a year later? Well, a project I was working on recently forced me to revisit this topic, but this time for a whole new reason.

Sending Faxes with ColdFusion
A few years ago I wrote an application that needed to generate faxes programmatically. This particular application was used heavily, and generated thousands of faxes a day. To handle that kind of load I set up a dedicated fax-server - a computer equipped with multiple fax boards (each capable of sending multiple faxes simultaneously) and special software that turned data (text, graphics, and even application files) into faxes. The fax-server had multiple interfaces: a print driver that redirected output to the server, low-level APIs, a polling agent that picked up files from specified directories, and even an e-mail gateway.

Because I had no idea which interface would work best, I wrote a custom tag that black-boxed all the processing. I could simply pass data to a tag that looked like the following code, and all the heavy lifting could be tweaked and revised as needed:

<CF_SendFax TO_NAME=""
TO_NUMBER=""
FROM_NAME=""
FROM_NUMBER=""
SUBJECT="">
...
</CF_SendFax>

In the end I used the e-mail interface, which provided the simplest integration from a CFML coding perspective. I was able to use <CFMAIL> to send e-mail to a special mailbox (the TO attribute contained the recipient fax number, the message body contained the cover sheet, and so on). Clean and simple.

A month or so ago I needed to send faxes programmatically again, only this time for a low-volume application running on a Windows 2000 server. So, instead of setting up an expensive high-end fax server, I opted to use the fax services built right into Windows 2000 (yes, Windows 2000 installs a true fax service if you have a fax modem installed). The interface to this service is COM, so using <CFOBJECT> and a series of supporting <CFSET> tags (and some help from Dain Anderson of www.cfcomet.com fame), I ended up with a custom tag that could send faxes via this service. The interface was completely different: COM versus e-mail, files containing content versus message bodies, passing values as properties versus mail headers, and Windows-only versus multiplatform. What did my new custom tag look like? I'll show you:

<CF_SendFax TO_NAME=""
TO_NUMBER=""
FROM_NAME=""
FROM_NUMBER=""
SUBJECT="">
...
</CF_SendFax>
Note: If you'd like to know more about the Windows 2000 fax service and Dain's CF+COM integration code, see the "Extending ColdFusion with COM" chapter in my new Advanced ColdFusion 5 Application Development (Sept. 2001, QUE).

It's All About Encapsulation
So, two very different faxing solutions with very different capabilities and very different interfaces. Yet from within my CF code they're essentially interchangeable.

What makes this all work is encapsulation: taking a process and black-boxing it within a clearly defined interface so the inner workings are hidden and isolated. Encapsulation in ColdFusion is achieved via custom tags in much the same way as Java developers write beans and Windows developers write DLLs. And just like writing beans or DLLs, encapsulating processes within custom tags requires careful planning. A well-designed encapsulation as a custom tag mustŠ

  • Provide a clean and consistent interface to simplify invocation
  • Not require extensive understanding of the internal workings
  • Not have dependencies on external objects, code, or assumptions - code should just work as is
  • Be well documented
Of course, custom tags are the primary way developers reuse code in ColdFusion (something I've written about extensively in this column), but there's more to it than reuse. Encapsulation also helps address two other important issues: group development and portability.

Group Development
Once upon a time (which was not that long ago in human years), all development was done by individuals - often someone with no social life, lots of caffeine, and a stack of books on everything from IP to JavaScript to creating animated GIFs. Fortunately, we've gotten past that stage; development is (or should be) a well-managed process, complete with schedules, project management, and groups of developers with complementary areas of expertise.

That's a good thing, except that all the little bits that make up ColdFusion development (and indeed all Web development) tend to be so interrelated that developers need to know lots of things about lots of technologies. This of course makes it hard to find developers, harder to keep them, and even harder to train new ones.

Which is why tiered code and encapsulation are so important. Suppose your GUI gurus create a sophisticated menuing and navigational system, or your DBA redesigns your database schemas, or your resident COM expert implements the aforementioned fax services integration. If all these were encapsulated properly, any developer could use the underlying technologies without special training, without needing lots of help, and without making all sorts of horrible mistakes. And if (or when) those same gurus and experts changed or updated their creations, the developers using them wouldn't have to restart from scratch.

Tiering your code - encapsulating functionality or processes or components - is the key to successful group development.

Portability
Portability refers to the ability of code to run on different systems without requiring changes. For the most part, portability is of no real concern to ColdFusion developers. After all, I don't know many ColdFusion installations that suddenly needed to move from Linux to Solaris, or from Windows to HP/UX.

So why is portability of interest? Back to the fax example I started off with. Portability is impacted not only by the underlying operating system, but also by any external services - like faxing. The fax service I just used is very operating system-specific. It runs on Windows 2000 only (not even on Windows NT or Windows ME). Does that mean I shouldn't use it? Absolutely not. There's nothing wrong with using whatever services and features that are available to you. If it's there, use it.

At the same time, you must protect yourself and make sure you aren't marrying your code to external processes you can't control. In my case, if the fax service goes away in the future, or if I have to run the app on Linux, or if I suddenly find that the volume of faxes has exceeded the abilities of this simple serviceŠwell, then, I'll find another faxing solution and create a tag with the same name and attributes to encapsulate the calls. None of my code will break; any needed changes will be local and controlled; and, for now, I can go on using what works because, well, it works for me right now.

In other words, why worry about portability until you really have to? For now, just make sure any code that could present portability problems is appropriately encapsulated. Worry about portability if that ever actually becomes necessary.

For the record, this isn't a new concept. Internally, this is exactly how ColdFusion works. <CFFTP> is implemented on Windows in a very different way than it is on UNIX, but CF developers don't need to know this. The underlying code is different, but the functionality and interfaces are the same, thanks to encapsulation.

Summary
Tiered development is nothing new, and n-tier development theory is the kind of stuff that makes stuffy academics break out in smiles. True n-tier development can be a pain to implement, but the basics of tiered development - breaking code into logical chunks with the appropriate levels of encapsulation - are very applicable to ColdFusion development. Keep this in mind the next time you design an application. The extra effort is minimal, and the benefits are staggering.

About Ben Forta
Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

rearea


Your Feedback
tf wrote: rearea
Latest Cloud Developer Stories
Swisscom, the Swiss telecom, is going into the cloud business. Its subsidiary Swisscom IT Services AG has signed up with Red Hat as a Certified Cloud Provider and launched a public cloud Infrastructure-as-a-Service (IaaS) cloud targeting enterprise-class customers primarily in ...
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP)....
In a surprise move on Tuesday, January 10, Oracle wheeled out its Big Data Appliance. That’s the one it said in October would be ready sometime in the first half. Only nobody believed it meant early in the first half. Heck, it’s not even clear anybody thought Oracle could make ...
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
CloudLinux, Inc., on Thursday released CafeFS 3, a virtualized file system for shared hosters that cages each customer within its own virtualized file system. CageFS becomes part of CloudLinux OS at no additional charge. CloudLinux OS, the only commercially-supported Linux OS m...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
As client demand for engagements increases, Revel Consulting (www.revelconsulting.com), a Kirkland, ...