optikalefx Posted December 3, 2009 Share Posted December 3, 2009 Can someone explain to me why I should use OOP instead of procedure based code. Im building a shopping cart and i created and Item object already and using it to hold data for each item. But this Object just has properties. I mean what methods could there possibly be for an item. Why would I need a Cart object either? There will never be more than 1 instance of the cart running. So what are the advantages to putting all my functions inside of a class? Thanks, and sorry if your offended by this, im trying to go OOP i just don't see why yet. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/ Share on other sites More sharing options...
trq Posted December 3, 2009 Share Posted December 3, 2009 Try searching the boards. This question has been flogged to death. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970269 Share on other sites More sharing options...
Mchl Posted December 3, 2009 Share Posted December 3, 2009 Noone says you should use OOP. In fact, if you can't see advantages of using it, you probably shouldn't. Don't worry. It took me several years to grasp why exactly OOP might be beneficial. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970308 Share on other sites More sharing options...
premiso Posted December 3, 2009 Share Posted December 3, 2009 It is very useful for storing many different cookies inside of a cookiejar. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970654 Share on other sites More sharing options...
FaT3oYCG Posted December 3, 2009 Share Posted December 3, 2009 lol, basically a search of wikipedia would help you understand why, php implements it very well as long as you know how to code with classes etc. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970657 Share on other sites More sharing options...
Daniel0 Posted December 3, 2009 Share Posted December 3, 2009 lol, basically a search of wikipedia would help you understand why, php implements it very well as long as you know how to code with classes etc. OOP is not about coding with classes, so maybe you should have a look at some WP articles as well As a matter of fact, one might design an object oriented language without the concept of classes. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970662 Share on other sites More sharing options...
FaT3oYCG Posted December 3, 2009 Share Posted December 3, 2009 Your member group leads me to think that I shouldn't argue, so I won't. I will simply state that I was relating the use of classes in php to the concepts of OOP and its features. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970666 Share on other sites More sharing options...
MadTechie Posted December 3, 2009 Share Posted December 3, 2009 Your member group leads me to think that I shouldn't argue LOL, love that! Well the use of a class doesn't mean its OOP for example, would you call this OOP ? <?php class test1{ var $user = ""; var $pass = ""; function login($user, $pass){ $this->user = $user; $this->pass = $pass; if("MadTechie" == $this->pass){ echo $this->user." Logged in"; }else{ echo $this->user." NOT Logged in"; } } } $test = new test1; $test->login("John","MadTechie"); Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970672 Share on other sites More sharing options...
FaT3oYCG Posted December 3, 2009 Share Posted December 3, 2009 Not really, I would call that a waste of a class as you could clearley just use the function / if statment, noting is inherited either so it doesn't really add anything that a function would not be capable of anyway. It is hard to relate a definition to OOP, I guess that the only way of truly interpreting it is to understand yourself when to use certain concepts. I couldn't really explain OOP to someone hence the suggestion to visit wikipedia. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970682 Share on other sites More sharing options...
mikesta707 Posted December 3, 2009 Share Posted December 3, 2009 not having inheritance and using OOP are not mutually exclusive. Hell not having classes and using OOP are not mutually exclusive either. Look at Javascript, its OOP system is prototypal (is that a word) rather than classical. Oh, and why should you use OOP? because it rocks. But in all seriousness, its not about one being better than the other. Its about what tool is best for the job. The whole hammer vs. screwdriver vs. wrench debate. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-970706 Share on other sites More sharing options...
optikalefx Posted December 6, 2009 Author Share Posted December 6, 2009 So the way I looked at it, If i have a set of common data that will share common functions that the rest of the code won't use. And I have the intent of REusing this (object) then, an object should be used. For example, I made a paypal buyer object. All the buyer information is related, and there are a few functions that pay requires so that the buyer information is correct. But no where else in the code are those functions needed. So an objected seemed the right choice. Quote Link to comment https://forums.phpfreaks.com/topic/183822-why-use-oop/#findComment-972494 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.