OO advice please

Soldato
Joined
18 Oct 2002
Posts
4,930
Location
Yorkshire
Just after a little bit of advice really.
I’m having a play trying to fully Object Orientate an old Ecommerce site I did a while back, now let’s say I’ve got a Customer class and a Product class, as well as a few others.
When you go to say click on a category link and display all the products for that category usually I’d just have a function that would have the sql statement to get all the products based on the category ID then loop through the results and output a formatted products table.
The way I’m doing it with the objects or how I think it should be done is to really create an array of product objects for that category then just loop through the array and output as before.
Now the question is where should the method be to create this array of products be ? Obviously it can’t be in the products class as it’s not a products responsibility to create copies of itself. I’m thinking it would go in the Customer class as in real life the customer would request the products list. But should it be the customers responsibility to format the list of products in to a readable version or should another class be involved which I use to send the product objects array to, to format the output. Or do I just return the product objects array to the normal php web page and do the formatting there, resulting to php code intermixed.
I know I can do it any of the ways mentioned but which would you say is the most correct?
 
HTMLHugo : Yeah thats what I usually do in .Net but might go with Inquisitor option , although it would be good to separate the database queries.

What you reccon one database class containing all queries or have seperate ones for each class that requires them ? usualy I just have the one.

Also back to my original question. where should I handle the displaying of the products i.e. formatting / looping through the array of product objects (if I use that method) directly in the class or handle it on the html/php page ?
 
right you've all given me some ideas to play about with now, was thinking of going the smarty route but then i've got to mess around learning all the smarting coding , ohh well suppose it'll do me good to learn it I supose.

thanks again all
 
Back
Top Bottom