Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2011, 01:14 PM   PM User | #1
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
When to use OOP?

Hi guys.

I am learning OOP with its classes, instances, methods etc etc.

As i am only learning it through the internet and not in a classroom i am looking at it and reading it, all looks pretty simple within reason.

But i am looking at some examples and i am thinking it would be easier just to do if,else, switch and loops rather than some of these examples.

I know that the lessons and tutorials are made to be very simple so that people can understand them which is great.

But with me its not the understanding how they work and why a static :: should be used etc etc.

Mine is knowing when to use OOP and when not to over complicate things.

Can anyone give me an example of when to start using OOP when coding.

Thanks
devinmaking is offline   Reply With Quote
Old 10-18-2011, 02:48 PM   PM User | #2
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
If you can do everything you need without OOP, do so. If you reach the point where something would be easier to implement using OOP, use it. That's the way I'd go. It has its uses, but it is more code for none to little gain if you don't specifically need it.
MattF is offline   Reply With Quote
Old 10-18-2011, 03:28 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'll half agree with the above.
OOP is always more work and more code than it would take to do the same task procedurally. This is the nature of OOP.
However, I won't agree with little to no gain. OOP provides you with many benefits including extreme reusability, centralized control, and dynamic handling with polymorphism. These can all be done in procedural as well, but to simulate the polymorphism in particular would take a lot of procedural code to do so.
So my approach is more of a short term pain for long term gain approach. If you have an extensive library of classes available to you, each project takes less and less custom code to build it. This becomes especially true when dealing with design patterns which you come to know (and love) when developing. The only thing to remember in OOP is that an interface is your best friend.
Fou-Lu is offline   Reply With Quote
Old 10-18-2011, 06:10 PM   PM User | #4
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,042
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Quote:
Originally Posted by Fou-Lu View Post
I'll half agree with the above.
OOP is always more work and more code than it would take to do the same task procedurally. This is the nature of OOP.
However, I won't agree with little to no gain. OOP provides you with many benefits including extreme reusability, centralized control, and dynamic handling with polymorphism. These can all be done in procedural as well, but to simulate the polymorphism in particular would take a lot of procedural code to do so.
So my approach is more of a short term pain for long term gain approach. If you have an extensive library of classes available to you, each project takes less and less custom code to build it. This becomes especially true when dealing with design patterns which you come to know (and love) when developing. The only thing to remember in OOP is that an interface is your best friend.
I mostly agree with this but I would like to add to it. If your only exposure to OOP is in web development you might not really see the benefit and the full potential of OOP. I wouldn't say OOP always takes more work than procedural code though, since as you said to replicate some of the advanced OOP features would take a lot of procedural code.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 10-18-2011, 06:29 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by oracleguy View Post
I mostly agree with this but I would like to add to it. If your only exposure to OOP is in web development you might not really see the benefit and the full potential of OOP. I wouldn't say OOP always takes more work than procedural code though, since as you said to replicate some of the advanced OOP features would take a lot of procedural code.
Oooh yeah that's a good point. I personally see great potential in OOP with web environments now, but I had not until I learned OOP outside of a web environment.
Fou-Lu is offline   Reply With Quote
Old 10-19-2011, 12:46 PM   PM User | #6
dionyseos
New to the CF scene

 
Join Date: Oct 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
dionyseos is an unknown quantity at this point
Quote:
But with me its not the understanding how they work and why a static :: should be used etc etc.
I think, it will be good for you when you read some literatur about the different design patterns. so you can learn for example why and when a static function can be usefull...
dionyseos is offline   Reply With Quote
Reply

Bookmarks

Tags
oop

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:47 PM.


Advertisement
Log in to turn off these ads.