On Friday we discussed how some of Twitter's problems might be solved by adding application servers to the mix, something that can easily be done in ColdFusion as well. I also mentioned how you can save yourself a lot of time and aggravation later by being smart about your application design up front. Here's how.
Most object-relational management systems (ORMs) create components that automate the process of talking to the database, doing reads, inserts, updates, and deletes. It's also beneficial to create what are known as business objects to encapsulate object-specific business logic, calculations, validation routines, and other functions.
A good system designer recognizes that these are two distinct functions, and organizes things appropriately, as follows:

Note how the business object talks to the ORM layer to get its data, tell it, for example, to load item 3478. That response comes by way of a Data Transfer Object (DTO), which contains the data in question. The business objects uses the data in the DTO, and passes it back to the ORM when it comes time to save the information.
All of this is well and good, of course, but how does this help us in our quest to quickly and easily add application servers and services? Well, it turns out that if you organize your application's business objects in this fashion, the following becomes relatively simple.

Notice how everything is fundamentally the same, except we've swapped out the database ORM component with a Web Services component. Now when we ask for item 3478, instead of talking to the database server it instead requests the data from an application server using web services. It then marshalls the response and loads it back into a DTO as expected by the business layer.
From the business object's perspective, everything is the same. And since the business object insulated the rest of the application and the web site from all of those finicky details, little, if anything, needs to be changed on that side of the fence.
This kind of application layering may be overkill for a twenty-page personal site, but is, in my opinion, almost mandatory for anything larger. You can never tell when you're going to need to change database systems, add application services, or, say, switch to an LDAP server for user management.
Always consider abstraction, encapsulation, and future expansion in your applications and designs. You can never tell when your simple idea for a web site can suddenly become the one everyone's Twittering about...
Comments