cgm225 Posted August 4, 2007 Share Posted August 4, 2007 I have gone through a lot of the threads in this forum, and several tutorials online, and while I feel comfortable with the syntax and instantiation of classes, I still don't understand their utility as opposed to using straight functions. Therefore, I was wondering if some of you would be willing to post some real-world, short, simple OOP examples that demonstrates their utility OVER functions? Regardless, thank you for your time and consideration. cgm225 Quote Link to comment https://forums.phpfreaks.com/topic/63347-looking-for-simple-oop-examples-that-demonstrate-utility-over-straight-functions/ Share on other sites More sharing options...
keeB Posted August 4, 2007 Share Posted August 4, 2007 You have to think of OOP as a long-term investment in to an application. The planning and the beginnings are the toughest, and projects evolve while you're developing them. If you're programming procedurally, you are developing as you are solving the problem in your head. I think, and others may disagree, that true OO programming requires the problem/excersize to be solved BEFORE you start coding. Maintaining procedural/functional code is tough. An example; If you have a popular function which is used everywhere, there may be serious side effects if along the line you have to change it. That's a lot of code you'll have to retest, modify, etc. To understand and it's practicalities, it's best to start learning along with review of design patterns. Here's a good start: http://www.cs.wustl.edu/~schmidt/PDF/patterns-intro4.pdf Maybe someone else will chime in with more of what you're looking for. Good luck Quote Link to comment https://forums.phpfreaks.com/topic/63347-looking-for-simple-oop-examples-that-demonstrate-utility-over-straight-functions/#findComment-315679 Share on other sites More sharing options...
Foser Posted August 5, 2007 Share Posted August 5, 2007 I believe that OO PHP is a difference between a decent programed and a great programmer. A great programmer makes things simple, and reusable. That is what exacly OOP provides for all us programmers. Sitepoint does a very straight forward easy to understand tutorial on OO PHP specifically. http://www.sitepoint.com/article/php-paging-result-sets Enjoy! Quote Link to comment https://forums.phpfreaks.com/topic/63347-looking-for-simple-oop-examples-that-demonstrate-utility-over-straight-functions/#findComment-315945 Share on other sites More sharing options...
Gamic Posted August 5, 2007 Share Posted August 5, 2007 It would depend on the size of the application. In larger applications OOP is the way to go for many reasons. I'm sure you can find out about all the benefits of using it on google In smaller, 1 or 2 page, applications (perhaps just a simple guestbook) You wouldn't need to use it. It would probably be better in those case to have some procedural code instead of OO code just because the applications are so small. One problem I've found with a lot of OO tutorials (in general) is that they are always talking about how bananas and apples are a type of fruit. This isn't really useful for programmers for a couple of reasons: 1, they don't know what fruit is () and 2, It's damned obvious that banana's and apples are fruit. But think of this: You have a forum, and in that forum you have "users". These are people who use the forum. (banana's are fruit!). Whenever you want to find out a user's name you could have a function called "find_users_name($userID);" which would do all the work. Or, you could have a user object and use that "$user->name"; You might have a page on this forum which displays all the users. You could, again, find out how many users there are, loop until you've shown them all and be happy. Or, you could have an object that does it for you. instead of $variable=get_max_users(); while($i<$variable){ echo(find_users_name($i)); $i++; } you could have $userCollection->printList(); But, as I say, it really does depend on the size of the application or the size of the problem you're trying to solve. And the more you use it the more you'll like it . Quote Link to comment https://forums.phpfreaks.com/topic/63347-looking-for-simple-oop-examples-that-demonstrate-utility-over-straight-functions/#findComment-316008 Share on other sites More sharing options...
Buyocat Posted August 5, 2007 Share Posted August 5, 2007 I've written these simple to use OO classes to encapsulate commonly performed tasks. I think they demonstrate when objects can be useful and do work for you. https://sourceforge.net/projects/utils-php/ Quote Link to comment https://forums.phpfreaks.com/topic/63347-looking-for-simple-oop-examples-that-demonstrate-utility-over-straight-functions/#findComment-316304 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.