apparatus Posted June 30, 2009 Share Posted June 30, 2009 Hello. I'm building an online shop with PHP and MySQL. As far as functionality goes, it's all right, but I think I can make the code more efficient / easier to maintain, so I have a theoretical question for you. Right now products in the shopping cart are saved in a session array along with additional order data. Would there be a point in having a more object oriented approach, with a class for orders and a class for products? I guess the answers to this question might be a matter of preference, but either way I'd like to hear some possible arguments. I'm quite new to object oriented programming so I might not have fully grasped the advantages. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/ Share on other sites More sharing options...
patrickmvi Posted June 30, 2009 Share Posted June 30, 2009 I think objects have their use but that overall, the general coding populace has embraced objects as the best thing since sliced bread. I've seen entire web-based applications developed using nothing but objects and in most cases it does nothing more than add a ton of overhead to the PHP engine and makes things way more confusing than they need to be. A lot of it is as you said a matter of preference. I like to use objects/classes only when I'm creating something that I know is common and will be re-used over and over again. Creating an object/class for one purpose only kind of defeats the purpose of having them. I'm sure you'll get some people that'll post the exact opposite but that is just how I feel about it. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/#findComment-866432 Share on other sites More sharing options...
apparatus Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks for your reply! I think you have an important point there. I don't want to use objects just for the hell of it - if it's not making things simpler/better for this particular purpose, it's just extra work. What I'm not exactly sure of is whether or not it would make sense to use objects in my particular case. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/#findComment-880236 Share on other sites More sharing options...
trq Posted July 22, 2009 Share Posted July 22, 2009 sessions vs objects? apples vs cars? I don't see how they relate. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/#findComment-880240 Share on other sites More sharing options...
apparatus Posted July 23, 2009 Author Share Posted July 23, 2009 sessions vs objects? apples vs cars? I don't see how they relate. Re-reading my initial post, I can see why you ask that... Right now, the orders are handled in a procedural manner (if I'm not confusing the terms) or in global functions, saving and retrieving shopping cart items etc. in session variables. I think what I was really wondering was this: what advantage is there for me to make this web shop code object-oriented? I realize now that I have read up on OOP a bit that the application type (web shop) might not matter that much after all, and that it is more an issue of code design / logic. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/#findComment-881035 Share on other sites More sharing options...
apparatus Posted July 23, 2009 Author Share Posted July 23, 2009 I think I'll just read up on general procedural vs. OOP arguments. Link to comment https://forums.phpfreaks.com/topic/164238-solved-sessions-andor-objects-for-shopping-cart/#findComment-881037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.