Janet,

It's conventional to consider DAOs to be low-level components without
dependencies on the rest of the system.  So in your form controller you'd do
something like:

    <cfset variables.fileHandler.upload(...)>
    <cfset variables.documentDAO.create()>
    <cfset variables.actionHandler.documentCreated(...)>

and documentDAO.create() would just be the SQL part.  Doing it this way
gives you the option of replacing your DAO layer without disturbing any of
your logic.

If you then wanted to encapsulate this sequence of calls you might create a
fourth component to do that.  There's a lot of variation in exactly how
you'd do that depending on how you like to lay out your application.  You
might have a utilities CFC that all your form controllers could use, you
might have a controller base class, you might have a specific subcontroller
object that just handles form uploads.  This is really a matter of style and
what makes most sense to you.

As a footnote, why would you want to replace your DAO layer?  To use a
different database with different SQL syntax, to stub out the database for
testing, or to transition to using a framework or code generation to take
care of DAOs for you.  Last but not least, even if you never need to swap
out the DAOs, doing it this way will least surprise other developers.

Jaime Metcher




  -----Original Message-----
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of J MacKay
  Sent: Friday, 30 March 2007 7:11 AM
  To: [email protected]
  Subject: [CFCDEV] newbie: needs an opinion on component structure


  I'm creating a few cfcs to handle file uploading in an MX6.1 application
and would like some opinions.  Here is an outline of the process:

  A site user uploads a document. The file is saved to a directory on the
server. A record is added to a database table with the file location and a
few other details. Whenever a document is uploaded, information is written
to a history table and an email is sent to a few other users (The last step
is a bit more complex, but thats the basic idea).

  I was thinking I should have at least 3 components (and maybe a manager
component as well?).

  FileHandler.cfc   - Handle file system operations (ie. upload)
  ActionHandler.cfc - Create history record and send emails
  DocumentDAO.cfc   - Create new document record (ie. CRUD operations)

  DocumentDAO would contain a reference to a FileHandler and ActionHandler
instance. So the DocumentDAO component wouldn't have to know anything about
uploads or sending emails.  It would simply call a method in FileHandler or
ActionHandler. Something like this

  <cffunction name="create"..>

      <cfset variables.fileHandler.upload(...)>
      <cfquery ..> INSERT INTO Documents ...</cfquery>
      <cfset variables.actionHandler.documentCreated(...)>

  </cffunction>

  I'm not sure if I'm on the right track with this. So I would appreciate
any opinions.  Hopefully the description wasn't too murky.



  Janet
  -------
  Still trying to wrap my brain around this OO stuff .. so speak slowly ;)




----------------------------------------------------------------------------
--
  Finding fabulous fares is fun.
  Let Yahoo! FareChase search your favorite travel sites to find flight and
hotel bargains.
  You are subscribed to cfcdev. To unsubscribe, please follow the
instructions at http://www.cfczone.org/listserv.cfm

  CFCDev is supported by:
  Katapult Media, Inc.
  We are cool code geeks looking for fun projects to rock!
  www.katapultmedia.com

  An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]


You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Reply via email to