Well to answer the first question, no you wouldn't want to convert the query 
into an array of objects for exactly the reason you stated: it is slow and 
there really is no reason to do this. Yes in Java you'd do that but Java is 
totally OO and much faster at this sort of thing. Basically, if you're 
dealing with sets of data to display (like a list of users) just use a 
query. Use a single object when you are modeling a single user (ie details 
page for a single user).

The answer to your second question about the address is to use composition 
and have the User object hold a reference to an Address object. So you are 
on track there. But you don't have to execute a query when you call 
getAddress(), the Address object is already there and populated (at the same 
time the User object is created) so you're just getting the state of the 
Address object by calling methods on it. Basically you don't need to run any 
queries beyond the first one that you use when you initialize the Address 
object.

Hope that helps.

Brian



On 6/1/05, Johnny Le <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> I am a little confused about cfc. Let's say I have a user object. I can 
> query the database for one user and then populate the user object. This 
> works great. I love it. However, when I need to display a list of users. 
> Should I use the query result to display or should I populate an array of 
> user objects with the query result, and use the array to display? That is 
> how you would do it in Java. Do you do the same in Coldfusion? Array is 
> slower in query. So it doesn't make sense. It is like I am having something 
> fast, but I convert it into something slow to use.
> 
> Now what if each user object has an address object. You can access it with 
> something like user.getAddress().getCity(). That means when you use 
> user.getAddress(), it goes back to the database and query the address for 
> that user. If you want to display 10 users with addresses. You would make 11 
> trips to the databases. Now if I use user.getAddress().getCity(), 
> user.getAddress().getState(), user.getAddress().getZip(), it would 
> actually make 31 trips to the database.
> 
> I could do address=user.getAddress(), but that is a little bit messy on 
> the presentation layer (mixing business logic within the presentation layer) 
> and it still takes 11 trips to the database.
> 
> If you are not using OO, you can just use one join statement and get all 
> the data from database with one trip. Am I right? Is this something we have 
> to accept if we want to work with OO or is there a workaround? Or am I 
> totally wrong in my approach to OO?
> 
> Johnny
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:208162
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

Reply via email to