I think this is too good of a topic to pass up, and I haven't seen any 
other responses, so..  I'll give it a shot.

At 10:11 AM 8/29/2002 -0400, you wrote:
>I'm trying to get my head around some good practices for using CFCs. I
>suppose it's old hat to those with OO backgrounds, but let's discuss a
>hypothetical application.

  There is some parallel to CFCs with Objects, however I think that a 
better comparison is Abstract Data Types (ADTs).  I suggest ( to everyone ) 
that you go off and do some research on them if possible.  Both Objects (in 
OO languages) and ADTs (in procedural languages) were created stemming from 
the same principles, which is to encapsulate information and the functions 
that work on that data.


>Let's say you're building an e-commerce application. Among the various data
>you have users and shipping addresses. Users can create, list, view, edit
>and delete their shipping addresses as well as associate them with orders.
>Administrators can also list, edit and delete shipping addresses, but their
>criteria would likely be different. For instance, viewing all shipping
>addresses in New Jersey, for instance, or those that have never had an order
>sent to them.
>
>The front-end stuff I got, no sweat. I want to encapsulate all of the
>database functions in CFCs.
>
>My questions then:
>
>How would you set up your CFC? In other words, what components would you
>create? What methods would you use? For instance, would the component used
>to bring back a query with a user's 0-n shipping addresses be the same
>component used to modify a particular shipping address? The SQL to pull a
>list of shipping addresses and the SQL to pull one based on its primary key
>is different only in the WHERE clause used. How do you maximize
>code--including SQL--reuse without going crazy?
>
>Further, and in general, how do you organize your CFCs?

  I'm sure there are plenty of ways to approach this.
  Let's see..

  I guess we would probably have these sort of tables in the application:
  Users
  ShippingAddresses
  Orders   ( For simplicity I'll leave it as an orders table, but it would 
probably have more)

  I would probably make a component called ShippingAddresses, to handle all 
Shipping Address dealings.  I would give it methods like this:

  GetShippingAddressFromOrder  (returns a structure, given the orderID)
  GetShippingAddressFromUserID (returns a query object of addresses, based 
on the userID)
  GetAllShippingAddresses (Returns a query object addresses, only for admin 
users only)
  UpdateShippingAddress (Returns boolean indicating whether operating was 
successful, function will have to perform security check to see if the 
current user has permission to update this particular address)
  CreateShippingAddress (returns boolean, userID is optional, function will 
perform security checks)
  DeleteShippingAddress (Returns boolean, flips a flag that doesn't really 
delete the address)

  That is it off the top of my head.  Then I'd create a user component, 
with stuff like this:

  GetUser (Returns a structure with user info, given the UserID)
  GetAllUsers (Returns a query object, admin user only method)
  CreateUser (Returns Boolean, one of the arguments will have to be of type 
ShippingAddress)
  UpdateUser
  DeleteUser
  etc..


  Then moving on, I'd probably create an Order CFC, with similar methods:

   GetOrder
   UpdateOrder
   CreateOrder
   GetAllOrders (admin only)

  I prefer to handle all display out of components, but someone might want 
to consider creating a component to handle display code also.

  This is what you get with 20-30 minutes of my brain power.  ( 
thoughts?  Comments? )



--
Jeffry Houser | mailto:[EMAIL PROTECTED]
Need a Web Developer?  Contact me!
AIM: Reboog711  | Phone: 1-203-379-0773
--
My CFMX Book: 
<http://www.amazon.com/exec/obidos/ASIN/0072225564/instantcoldfu-20>
My Books: http://www.instantcoldfusion.com
My Band: http://www.farcryfly.com 

______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to