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?
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?