Just as a side note, database Gateway isn't CF specific, it was already
covered by Fowler in "Patterns of Enterprise Application Architecture", back
in 2002:
http://www.amazon.com/exec/obidos/ASIN/0321127420/
----------------------------
Massimo Foti, web-programmer for hire
Tools for ColdFusion, JavaScript and Dreamweaver:
http://www.massimocorner.com
----------------------------
c) A database's view that that returns the age as calculated field :-))
Of course solution c doesn't fit more complex/sophisticated needs, but for
something that simple is still a viable solution.
Fowler talks about Table Data Gateway plus Row Data Gateway, and consider
DAO quite a different beast. I tend to agree with him.
http://martinfowler.com/eaaCatalog/
You will not find DAO on that book because it was already covered elsewhere,
like here:
http://www.corej2eepatterns.com/Patterns2ndEd/DataAccessObject.htm
Hope it may help
Massimo
I understand your point, but we are walking a thin line, is age a "business
rule" or it's just data?
Again, I am talking only about something as simple as age calculation, more
complex stuff definitely belong to business rules.
Massimo
Since I'm sort of responsible for the separate DAO / Gateway nonsense
in CF - due to a recommendation I made in 2003 in the Mach-II
Development Guide - I'd really like to see it completely eradicated!
I made the recommendation at the time when OO was completely new to
(most) CFers and felt it would be a good "reminder" to get them to
think of objects as single DB rows and queries for aggregate
operations so they wouldn't be tempted to use a query for a single row
or, worse, an array of objects for giant query results (due to
performance).
It was a reasonable stepping stone at the time but things have moved
on and I try very hard now to encourage CFers to learn from mainstream
OO design patterns and therefore explain that DAO (in Core JEE
Patterns) and the Table Data Gateway (in more general pattern
material) are really the same and as long as folks understand *why* we
don't generally use arrays-of-objects, it's actually fine to put
find*() methods (returntype="query") in the same data layer object as
the CRUD stuff (which operates on a single row / object).
The reason for pushing this unified approach is that it is easier to
avoid the "5:1 Syndrome" (bean + dao + gateway + manager/service +
controller) by having a DAO that operates on an object and its closely
related objects for both single and multiple record operations,
dividing the application by logical grouping rather than just the five
objects per table approach.
In my apps, my controller deals with an "area" of the application,
usually dealing with multiple object types, my service/manager object
deals with a functional subsystem, again with multiple object types -
and focusing on collaborative functionality that doesn't fit in a
single object, my data gateway deals with a related group of object
types and my beans have as much logic as they need to do their own
job.
Also, if a DB table is used only in conjunction with another (e.g.,
UserStatus used with User) then I don't have a UserStatus bean - the
status is subsumed into the User bean and you can ask if the
user.isActive() or user.isPending() or whatever (and using
onMissingMethod() allows you to add arbitrary status values without
adding more methods if you care about that sort of thing).
So, fat beans, thin services and controllers, and a "sensible" data layer.
Let's all work together to kill off the old-fashioned and unnecessary
separation of DAO and Gateway and get CF usage more inline with
"common wisdom" in the broader patterns community.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
cheers,
barneyb
On Mon, Mar 2, 2009 at 11:21 PM, Alan Livie <alan...@yahoo.com> wrote:
> I've been playing with Groovy and Hibernate for about a week now and what is
> brilliant about it is when building something from scratch you no longer
> think about the db in the way you do usually.
>
> You just create a database and forget about it. You focus on your domain
> model, adding a few Hibernate annotations along the way and when you call
> save() in your Hibernate session it creates tables, columns and saves all
> the data. Inheritance hierarchies etc not a problem.
>
> If cf9 can work with Hibernate in the same way (maybe annotations in
> cfscript and/or a new attribute on the cffunction tag) then in a year or two
> no one will even care about DAOs and Gateways.
>
> If you want to understand things like Data mapper, Unit Of Work etc to get
> an idea of what Hibernate is doing then read Fowler's Patterns Of Enterprise
> Application Architecture ... then be thankful someone else has done the ORM
> work because it looks like a complete nightmare trying to build an ORM!
>
> Alan
--
Barney Boisvert
bboi...@gmail.com
http://www.barneyb.com/
I'd highly recommend everyone that does OO-ish CF to take a good hard look at Hibernate.
I'll also plug Barney's cfGroovy project and cfHibernate plugin which
allows you to write persistent Groovy entities and use them easily
from within CF.