When you say "a whole bunch of singleton DAOs", what do you mean? You
should only ever create one singleton DAO for your *entire* application.
- Derek
On Nov 3, 2007, at 3:44 PM, Mike Kear wrote:
Brian, Please don’t ask me that. You’re knowledgeable about OOP
techniques, I’m only just learning. Instead of asking me a
question like that, with an implied criticism embedded in it, why
don’t you just suggest a better way instead.
In my view, there are two things that make OOP so difficult to
understand for people who learned coldfusion in the procedural
school – the esoteric arguments back and forth and the huge pile of
technical terms. I even get the feeling that there are some people
that just make up their own technical terms and use them as though
we’re all supposed to know what they are and we must be dummies if
we don’t. There is one leading blogger in the CF world who makes
a LOT of statements about OOP but I have to confess that in spite
of reading at least 50 of his posts, there isn’t a single one that
I understood. He might as well have been posting in Latin for all
the good it did me.
So why I would do it the way I did?
I figured it was wasteful of resources to just create a whole bunch
of singleton DAOs on the off-chance that someone might need to use
them. I thought a better approach was to instantiate the DAO when
someone went to the area of the admin module that is going to
require this DAO. I instantiated the DAO at the top of the page
that requires it, and reused it muitiple times down the page.
Somene else suggested I just access the session.userbean as and
when I required it, directly from the DAO. I thought that was BAD
BAD BAD. I thought the notion of encapsulation meant no cfc should
have to look outside itself for anything. I thought the DAO should
be given anything it needs to know. Well in this case, any cfc
modifying the database in any way has to have a stamp on the record
it changes or adds. . I need to stamp it with the time (can’t
use getdate() in the database because that’s not Australian Eastern
Standard Time – so I pass in the current AEST) and the ID of the
user making the change.
So that’s the problem I’m trying to work out … how do I inject
the userID into the DAO so it can use it?
I’m afraid I’m still not too sure how I persuade Coldspring to give
me a DAO initialised and ready to use, complete with the userid and
time (I normally use request.austime – a variable I create in the
OnRequest() method of the application.cfc
Cheers
Mike Kear
Windsor, NSW, Australia
0422 985 585
Adobe Certified Advanced ColdFusion Developer
AFP Webworks Pty Ltd
http://afpwebworks.com
Full Scale ColdFusion hosting from A$15/month
From: [email protected] [mailto:coldspring-
[EMAIL PROTECTED] On Behalf Of Brian Kotek
Sent: Sunday, 4 November 2007 4:46 AM
To: [email protected]
Subject: [coldspring-dev] How do I inject a userbean into a DAO?
A more fundamental issue is: why would you want to create a new
instance of the DAO on every request instead of using it as a
Singleton?