RE: Adding Multiple Objects

2006-01-03 Thread Russ
Not too sure what you're talking about here... 

You should probably have a user object that has a contactinfo object inside
of it.  These would be beans... 

When you save the user bean to the database, you would run the validate
method on it first, which would validate all the fields inside user are
correct, and should also call validate on the contactInfo, to make sure that
that's correct.  

Then when you save it to the database, you should save the user to the user
table and then save the contactinfo to the contact info table in the same
transaction (although they can be separate function calls).  

Russ


-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:37 PM
To: CF-Talk
Subject: Adding Multiple Objects

Hi,

If I had a USER cfc and a CONTACTINFO cfc and no user should exist without
having contact info - whats a good way to add a user to the DB?

Should I call AddUser() which in turn calls AddContactInfo()?

OR, should I call AddContactInfo() first, then take the ContactID and pass
it into AddUser()?

Cheers,
Baz






~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:228297
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Adding Multiple Objects

2006-01-03 Thread Cornillon, Matthieu \(Consultant\)
Well, I would say that you can add contact info without adding a user
(multiple contacts, right?) but you can't add a user without adding
contact info.  So, it seems to me that you first instantiate the user
and then instantiate the contact info entry, not the other way around
(i.e., AddUser() first).

Some reasons why:

1) What if you want to add a second contact later?  Your class may not
support this now, but if you want to add the ability to do it, you would
have to rework things significantly if you called AddContactInfo()
first.

2) If you call AddContactInfo() first and it calls AddUser()
automatically, what if AddUser() throws an error?  Then you are stuck
with an orphaned contact entry.

HTH,
Matthieu


-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:37 PM
To: CF-Talk
Subject: Adding Multiple Objects


Hi,

If I had a USER cfc and a CONTACTINFO cfc and no user should exist
without having contact info - whats a good way to add a user to the DB?

Should I call AddUser() which in turn calls AddContactInfo()?

OR, should I call AddContactInfo() first, then take the ContactID and
pass it into AddUser()?

Cheers,
Baz






~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:228300
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Adding Multiple Objects

2006-01-03 Thread Bobby Hartsfield
That would probably depend on your database. How many tables do you have for
the users and contact info? 

1 for contactinfo
1 for users

and a foreign key to relate the two... if so... the table with the
foreign key would be the LAST one to add since you'd need the id from the
other to complete it (else you'd have to get the ID and update a record
unnecessarily)

Or...

1 table for contactinfo
1 table for users
1 table to relate a user to his/her contact info

In this case it wouldn't much matter which one you added first since the
record won't be complete until they both exist and have been tied together
in the third table.

If one couldn't exist without the other though, you might consider
consolidating them into one cfc and one table. (if that's possible with
whatever you're doing)
 
..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
 
 

-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:37 PM
To: CF-Talk
Subject: Adding Multiple Objects

Hi,

If I had a USER cfc and a CONTACTINFO cfc and no user should exist without
having contact info - whats a good way to add a user to the DB?

Should I call AddUser() which in turn calls AddContactInfo()?

OR, should I call AddContactInfo() first, then take the ContactID and pass
it into AddUser()?

Cheers,
Baz






~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:228310
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Adding Multiple Objects

2006-01-03 Thread Baz
Hi Matthieu, Bobby,

The USER table has a 1-1 relationship with the CONTACTINFO table. So 1 user,
may have no more, and no less, than 1 set of contact info. To add a USER, I
have no choice but to add the CONTACTINFO first, get the new autogenerated
ID, and use that to add a User. In the case of an error, the new CONTACTINFO
is deleted - so no orphans.

Keep in mind that CONTACTINFO is used for more than just USERs. So while
there are ATLEAST as many CONTACTINFO records as there are USER records,
there are actually more CONTACTINFO records.

For that reason, each of those tables needs to have its own CFC as well.

The question is: How much coupling should go on between those 2 cfcs? Where
should I call the CONTACTINFO methods? Here are 3 different ways to
accomplish the same thing:

!--- Example A: Index.cfm with no dependencies between CFCs ---
cfscript
// Add Contact to DB
ContactObj=createObject('ContactInfo');
ContactObj.setFullName('Matthieu');
ContactObj.AddToDB();

// Add User to DB
UserObj=createObject('User');
UserObj.setRelatedContactID(ContactObj.getContactID());
UserObj.AddToDB();
/cfscript

!--- Example B: Index.cfm is aware of dependencies between CFCs ---
cfscript
UserObj=createObject('User');

// Add Contact to DB through User
UserObj.getContactObj().setFullName('Matthieu');
UserObj.getContactObj().AddToDB();

// Add User to DB
UserObj.setRelatedContactID(ContactObj.getContactID());
UserObj.AddToDB();
/cfscript

!--- Example C: Index.cfm is NOT aware of existing dependencies ---
cfscript
// Add Contact AND User
UserObj=createObject('User');   
UserObj.setFullName('Matthieu');
UserObj.AddToDB();
/cfscript

PROS  CONS

Example A: Index.cfm with no dependencies between CFCs
PRO: No coupling between CFCs
CON: Dependencies are not hidden, app has to be very aware of them
CON: Not always possible, sometimes you HAVE TO define a dependency

Example B: Index.cfm is aware of dependencies between CFCs
PRO: MINOR coupling between CFCs
PRO: Easier, everything for USER get handled through USER
CON: You must be aware of the complex structure of the cfc
CON: You still have to know to add CONTACTINFO before u add USER

Example C: Index.cfm is NOT aware of existing dependencies
PRO: Complex dependencies are hidden! You just have to AddUser() and
this will take care of CONTACTINFO
CON: High coupling between components, especially if you duplicate
getter/setter methods. Changes in CONTACTINFO.cfc will
necessitate changes in USER.cfc.

To me it seems like the valid choices are Example A and Example C, because
why even introduce a non-required dependency if it doesn't significantly
simplify matters...

Thoughts?

Baz



-Original Message-
From: Cornillon, Matthieu (Consultant)
[mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:56 PM
To: CF-Talk
Subject: RE: Adding Multiple Objects

Well, I would say that you can add contact info without adding a user
(multiple contacts, right?) but you can't add a user without adding
contact info.  So, it seems to me that you first instantiate the user
and then instantiate the contact info entry, not the other way around
(i.e., AddUser() first).

Some reasons why:

1) What if you want to add a second contact later?  Your class may not
support this now, but if you want to add the ability to do it, you would
have to rework things significantly if you called AddContactInfo()
first.

2) If you call AddContactInfo() first and it calls AddUser()
automatically, what if AddUser() throws an error?  Then you are stuck
with an orphaned contact entry.

HTH,
Matthieu


-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:37 PM
To: CF-Talk
Subject: Adding Multiple Objects


Hi,

If I had a USER cfc and a CONTACTINFO cfc and no user should exist
without having contact info - whats a good way to add a user to the DB?

Should I call AddUser() which in turn calls AddContactInfo()?

OR, should I call AddContactInfo() first, then take the ContactID and
pass it into AddUser()?

Cheers,
Baz








~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:228316
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54


RE: Adding Multiple Objects

2006-01-03 Thread Bobby Hartsfield
I'd agree with that. I'd personally lean more towards example C though.
Since users can't exist without contact info, I don't see anything wrong
with modifying USER.cfc to encompass CONTACTINFO.cfc so long as it doesn't
hose the CONTACTINFO.cfc as a stand alone component. There's definitely
nothing wrong with simplifying matters :-)

..:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
 
 

-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 7:41 PM
To: CF-Talk
Subject: RE: Adding Multiple Objects

Hi Matthieu, Bobby,

The USER table has a 1-1 relationship with the CONTACTINFO table. So 1 user,
may have no more, and no less, than 1 set of contact info. To add a USER, I
have no choice but to add the CONTACTINFO first, get the new autogenerated
ID, and use that to add a User. In the case of an error, the new CONTACTINFO
is deleted - so no orphans.

Keep in mind that CONTACTINFO is used for more than just USERs. So while
there are ATLEAST as many CONTACTINFO records as there are USER records,
there are actually more CONTACTINFO records.

For that reason, each of those tables needs to have its own CFC as well.

The question is: How much coupling should go on between those 2 cfcs? Where
should I call the CONTACTINFO methods? Here are 3 different ways to
accomplish the same thing:

!--- Example A: Index.cfm with no dependencies between CFCs ---
cfscript
// Add Contact to DB
ContactObj=createObject('ContactInfo');
ContactObj.setFullName('Matthieu');
ContactObj.AddToDB();

// Add User to DB
UserObj=createObject('User');
UserObj.setRelatedContactID(ContactObj.getContactID());
UserObj.AddToDB();
/cfscript

!--- Example B: Index.cfm is aware of dependencies between CFCs ---
cfscript
UserObj=createObject('User');

// Add Contact to DB through User
UserObj.getContactObj().setFullName('Matthieu');
UserObj.getContactObj().AddToDB();

// Add User to DB
UserObj.setRelatedContactID(ContactObj.getContactID());
UserObj.AddToDB();
/cfscript

!--- Example C: Index.cfm is NOT aware of existing dependencies ---
cfscript
// Add Contact AND User
UserObj=createObject('User');   
UserObj.setFullName('Matthieu');
UserObj.AddToDB();
/cfscript

PROS  CONS

Example A: Index.cfm with no dependencies between CFCs
PRO: No coupling between CFCs
CON: Dependencies are not hidden, app has to be very aware of them
CON: Not always possible, sometimes you HAVE TO define a dependency

Example B: Index.cfm is aware of dependencies between CFCs
PRO: MINOR coupling between CFCs
PRO: Easier, everything for USER get handled through USER
CON: You must be aware of the complex structure of the cfc
CON: You still have to know to add CONTACTINFO before u add USER

Example C: Index.cfm is NOT aware of existing dependencies
PRO: Complex dependencies are hidden! You just have to AddUser() and
this will take care of CONTACTINFO
CON: High coupling between components, especially if you duplicate
getter/setter methods. Changes in CONTACTINFO.cfc will
necessitate changes in USER.cfc.

To me it seems like the valid choices are Example A and Example C, because
why even introduce a non-required dependency if it doesn't significantly
simplify matters...

Thoughts?

Baz



-Original Message-
From: Cornillon, Matthieu (Consultant)
[mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:56 PM
To: CF-Talk
Subject: RE: Adding Multiple Objects

Well, I would say that you can add contact info without adding a user
(multiple contacts, right?) but you can't add a user without adding
contact info.  So, it seems to me that you first instantiate the user
and then instantiate the contact info entry, not the other way around
(i.e., AddUser() first).

Some reasons why:

1) What if you want to add a second contact later?  Your class may not
support this now, but if you want to add the ability to do it, you would
have to rework things significantly if you called AddContactInfo()
first.

2) If you call AddContactInfo() first and it calls AddUser()
automatically, what if AddUser() throws an error?  Then you are stuck
with an orphaned contact entry.

HTH,
Matthieu


-Original Message-
From: Baz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:37 PM
To: CF-Talk
Subject: Adding Multiple Objects


Hi,

If I had a USER cfc and a CONTACTINFO cfc and no user should exist
without having contact info - whats a good way to add a user to the DB?

Should I call AddUser() which in turn calls AddContactInfo()?

OR, should I call AddContactInfo() first, then take the ContactID and
pass it into AddUser()?

Cheers,
Baz










~|
Logware (www.logware.us): a new and convenient web-based time tracking

Re: Adding Multiple Objects

2006-01-03 Thread James Holmes
Yes, go for C; use object composition, so that the contactinfo
instance is a property of the user instance.

On 1/4/06, Bobby Hartsfield [EMAIL PROTECTED] wrote:
 I'd agree with that. I'd personally lean more towards example C though.
 Since users can't exist without contact info, I don't see anything wrong
 with modifying USER.cfc to encompass CONTACTINFO.cfc so long as it doesn't
 hose the CONTACTINFO.cfc as a stand alone component. There's definitely
 nothing wrong with simplifying matters :-)

--
CFAJAX docs and other useful articles:
http://jr-holmes.coldfusionjournal.com/

~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:228320
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations  Support: http://www.houseoffusion.com/tiny.cfm/54