Comments
bruce.armstrong wrote: Somebody just said it better than I did, and with more chops to say it: Open Letter to Mark Zuckerberg, Sheryl Sandberg & Facebook Mobile
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Design Patterns: Using DAO, DG and VO in ColdFusion
CF is great, but it's not advanced enough for DAO and DG

In the more modern day ColdFusion development, we tend to rely heavily on various Design Patterns to automate or "template" our daily coding chores. The patterns most frequently touched on are the Data Access Objects (DAO), DataGateway (DG) and VO (Value Object) ­ or ­ Bean (VO with setter/getter routines).

I've often used them, but can't but help get the feeling that they are probably not suited for the ColdFusion Development world as to me; their reasons for being used aren't valid enough to warrant using them blindly.

I mean, why Use a DAO?

I'll attack DAOs first, as these are one of the core primitives found in most frameworks.

The concept of a DAO is as most already know, to allow the four key actions to take place (CREATE, UPDATE, DELETE, READ). In doing this, along the way we are supposed to accept "arguments" of each specific type (i.e., CustomerID is Numeric?).

If that succeeds, the logic to perform one of the above actions commences, and as a result we have a success result.

Yet, what are we really achieving by having a DAO in place? In that is it about strict typed variables or is it about housing logic inside a CFC for safekeeping. At the very least that's all we are really doing is preventing data that has the wrong type, being inserted into a database or xml packet.

What if we were to say, use an XML Schema to dictate this?

In that using a "TableAdapter" object, we feed in arguments or serialized object, which the TableAdapter dissects, validates and allows passing otherwise it throws an exception.

Immediately one thing springs to mind, in that it breaks encapsulation of knowing what variables are passed in and out of an object, in that they become "unknown."

Which is true, how are we to know that CustomerID is String or Numeric?

We, the developer would look this up under the various documentation tools out there such as CFCDoc, which tells us exactly what's coming in and out (i.e., how to implement).

Yet, are we not getting in danger of coupling our entire business logic with say our database? What would happen if down the road we change CustomerID from Numeric to String (i.e., AutoNumber gets replaced with UUID) what then? How do we adjust our rules and policies to cope?

We could make a ruling, which simply states that all "ID" fields are "Strings" regardless, and only when they get tucked away inside our nominated database, that actual type conversion kicks in. Yeah, that'd work but where does that rule end?

This is probably a problem used in most other languages, and there are other ways to overcome this (i.e., overloading a method for one) ­ yet ­ we are in ColdFusion, not one of these languages.

This line of reasoning is the foundation of why I disliked in many ways the concept of DAOs as they are "too" specific in terms of data typing. It's too easy to let the compiler take care of the "rulings" on what type of variable should be sent to the view.

How about an alternative solution? In that what if we put together an object, which we could ask should we need to know what type of variable it is?

In that, what if an object called "DataTable" existed, and inside that we had another object (composition) called "DataRow," which essentially we ask to know what "type" a column is.

This concept is loosely borrowed form Windows .NET 2.0's "DataSets."

Essentially all your "Database" activities are stored inside an XML Schema, which essentially defines how and where data gets stored and what "type" they are expected to be stored in.

Furthermore, it's not limited to "Databases." It's also used for "Files" (XML, CSV, MS Access etc.).

The point is this that by hard coding our persistence storage via DAO, we are really shifting our approach in terms of defining the rules required to be in place before data is persisted. If these rules change, it can be an achievement unto itself to go through code and adjust properties/arguments to suite.

Then there is the risk of having a mutipersist-based application, which results in duplication of code in the way of DAO just because there are different types for each persistence technology (MySQL versus Oracle, etc.).

Its hard post to swallow, I do admit that as every bone in your OOP bodies would be fighting tooth and nail that this is totally against the OOP grain, which I do agree, except we are in "ColdFusion" ­ a point that I cannot stress enough. ColdFusion isn't sophisticated enough to cope with the rulings of its foundation (J2EE) unless you introduce specific Java hacks. If you introduce JAVA into the equation, then yes we are in a whole new discussion, but most don't use JAVA as their buffer between ColdFusion and a Database.

This brings me to my original question, why use a DAO? Same question goes for a DG, why Use them?

In most cases, what's the difference between a "GetPersonByEmail" and "GetPersonByID" and how would you store that principal concept in a DG component? Smart answer would probably be two separate queries, with two separate "WHERE" statements in SQL terms.

Yet, what happens if we were to drop a field from the equation or better yet, introduce one?

Those of you who have used DGs and DAOs in large applications will know what I'm talking about, in that it's "a lot of work" to get all those arguments in place throughout the code base.

To me, there is an alternative and I'm currently hacking away at it. It simply involves XML to describe how my persistence gets stored and what constraints are in place should they arise are declared via XML.

A Value Object though is a hard one, because they really only serve an "emulated" approach, in that the CFPROPERTY tag really a has purpose other than to describe what potentially the variables inside a CFC will be ­ yet ­ they don't enforce such rulings.

Nope, to me ColdFusion is great, but it's not advanced enough to warrant the patterns such as DAO and DG.

How's that sit with you?


This blog is reprinted with the author's permission and appeared originally on
www.mossyblog.com/archives/553.cfm.

About Scott Barnes
Scott Barnes is Product Manager for the Rich Client Platform team at Microsoft, with a focus on Silverlight. Originally from the small outback town of Cunnamulla in Australia, Barnes was Microsoft's first RIA Evangelist, focused primarily on the Web space. He blogs at http://blogs.msdn.com/msmossyblog/.

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

Register | Sign-in

Reader Feedback: Page 1 of 1

I'm with Brian. I personally use a modified version of F. Scott's CFC generator, see[http://www.franciswscott.com/blog/1/2005/05/CFC-DAO-Generator-Take-two.cfm]

I'm also with Dissenter. Being (or pretending to be) typeless is very usefull 99% of the time, Duck Typing CFC's makes inheritance and therefore code re-using easy.

Why not just use something like Reactor which dynamically generates the appropriate DAO, Gateway, VO, etc. based on the mechanism in question (Oracle vs. MySQL, etc.) and also generates it based on the table metadata? Change a column from numeric to string? Add a column? The CFCs that Reactor generates automatically adjust. I think this is a much better solution than moving to some other pattern (or no pattern at all).

|| ColdFusion isn't sophisticated enough to cope with the rulings of its foundation (J2EE) unless you introduce specific Java hacks. ||

Does everyomne agree? I;'m not certain you're right hereS cott.

In the more modern day ColdFusion Development, we tend to rely heavily on various Design Patterns to automate or 'template' our daily coding chores. The patterns most frequently touched on are the Data Access Objects (DAO), DataGateway (DG) and VO (Value Object) ­or Bean (VO with setter/getter routines).

In the more modern day ColdFusion Development, we tend to rely heavily on various Design Patterns to automate or 'template' our daily coding chores. The patterns most frequently touched on are the Data Access Objects (DAO), DataGateway (DG) and VO (Value Object) ­or Bean (VO with setter/getter routines).


Your Feedback
Tim Smolders wrote: I'm with Brian. I personally use a modified version of F. Scott's CFC generator, see[http://www.franciswscott.com/blog/1/2005/05/CFC-DAO-Generator-Take-two.cfm] I'm also with Dissenter. Being (or pretending to be) typeless is very usefull 99% of the time, Duck Typing CFC's makes inheritance and therefore code re-using easy.
Brian Kotek wrote: Why not just use something like Reactor which dynamically generates the appropriate DAO, Gateway, VO, etc. based on the mechanism in question (Oracle vs. MySQL, etc.) and also generates it based on the table metadata? Change a column from numeric to string? Add a column? The CFCs that Reactor generates automatically adjust. I think this is a much better solution than moving to some other pattern (or no pattern at all).
dissenter wrote: || ColdFusion isn't sophisticated enough to cope with the rulings of its foundation (J2EE) unless you introduce specific Java hacks. || Does everyomne agree? I;'m not certain you're right hereS cott.
SYS-CON Australia News Desk wrote: In the more modern day ColdFusion Development, we tend to rely heavily on various Design Patterns to automate or 'template' our daily coding chores. The patterns most frequently touched on are the Data Access Objects (DAO), DataGateway (DG) and VO (Value Object) ­or Bean (VO with setter/getter routines).
SYS-CON Italy News Desk wrote: In the more modern day ColdFusion Development, we tend to rely heavily on various Design Patterns to automate or 'template' our daily coding chores. The patterns most frequently touched on are the Data Access Objects (DAO), DataGateway (DG) and VO (Value Object) ­or Bean (VO with setter/getter routines).
Enterprise Open Source Magazine Latest Stories . . .
In this CTO Power Panel at the 10th International Cloud Expo, moderated by Cloud Expo Conference Chair Jeremy Geelan, industry-leading CTOs & VPs of Technology will discuss such topics as: Which do you think is the most important cloud computing standard still to tackle? Who should...
Private clouds solve many problems for enterprises and bring unique operational challenges along with them. There are dozens of companies of all sizes that will build you a private cloud and turn over the keys – then what? Trying to convert a traditional enterprise IT operations team t...
The networking industry has gone through different waves over last 30+ years. In the ’80s, the first wave was all about connecting and sharing; how to connect a computer to other peripheral devices and other computers. There were many players who developed technology and services to ad...
The impact of Big Data is extremely broad for business, information management and technology. Being able to analyze your growing mountain of data can give you a distinct competitive advantage, but Big Data can be more than traditional tools can handle. In his session at the 10th Int...
Cloud computing is creating the new Wall Street boom, according to NIA. The only industry that is as bright as cloud computing on Wall Street is social networking, NIA said in a recent report. 2012 will be known as the year cloud computing became widely adopted worldwide. Cloud comput...
If your organization already uses virtualized infrastructure, you are well on your way to providing IT as a Service. But as businesses demand faster results in today’s competitive market, organizations look to gain more benefits from cloud computing than just virtualized infrastructure...
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