I think that the ideal is to keep each sides ignorant of the other (more
loosely coupled). What you really need is a third object to mediate the
exchange of data between the two.  How about this instead:

class UserManager
{
   User getUser(integer userID)
   {
      user = UserFactory.newUser();
      data = UserGateway.getForID(userID);
      user.init(data);
      return user;
   }
}

class UserFactory
{
   User newUser()
   {
      return CreateObject("User");
   }
}

class UserGateway
{
   query getForID(integer userID)
   {
      /* Get recordset for individual user */
      q = RunQuery("select from users where user_id = #userID#");
      return q;
   }
}

class User
{
   User init(query data)
   {
      /* Set data members here */
      ...
      return this;
   }
}


When you want to get a User object with data from the database, you simply
call "UserManager.getUser(userID)" and it takes care of the details of how
the object is created, where its instance data comes from, and how that data
is put in the object.


Paul Kenney
WebMaster, CorporateWarriors.com
916-663-1963


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Davis, Eric
Sent: Tuesday, January 20, 2004 7:48 AM
To: '[EMAIL PROTECTED]'
Subject: [CFCDev] Gateways, Factories, and Business Objects


Greetings:

I'm trying to implement Gateway and Factory objects which will, when
combined, manage my Business Objects. UserFactory will, naturally, create
for me a User object; UserGateway will handle the database integration
aspects for any and all User objects.

Should the UserFactory object utilize a (the?) UserGateway object when
creating for me a User object at, say, login or edit time?

pseudo:
class UserFactory {
 function new() {
   return CreateObject("user");
 }
 function new(UserGateway, userID) {
   return CreateObject("user").init(UserGateway.retrieve(userID));
 }
}

...or should I leave retrieval of a specific user record entirely to the
UserGateway?

more pseudo:
class UserGateway {
 function select() {
   return (queryObject);
 }
 function retrieve(userID) {
   q = select from users where user_id = userID
   return CreateObject("user").init(q);
 }
 functino update(user) {
   try {
     q = update users set ...
   } catch {
     return false;
   }
   return true;
 }
 ...
}

How do you relate Gateways, Factories, and Business Objects to each other?

Thanks for your help and/or advice.
ecd.

-- 
Eric C. Davis
Programmer/Analyst I
Georgia Department of Transportation
Office of I.T. Applications
Web Applications Group
404.463.2860.199
[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to