View Single Post
Old 01-23-2010, 11:06 PM   #4 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Village Idiot hit the nail on the head pretty much - in most circumstances you aren't going to know what the best method to use is, until you've had enough experience under your belt to visualize the process and desired results without even putting a finger to your keyboard.

One of the problems a lot of newcomers to OOP face is that after they've learned the ropes, they go OOP crazy, and find some reason to turn everything they've done into some form of object oriented programming. Right down to the loneliest of procedural functions. Avoid this peril at all costs! OOP is an amazing construct, but it's not always the best construct - the beauty of PHP is that you can mix and match to your hearts content, and since I learned that fact, most of my major apps have since wound up being a hybrid of both.

When you use OOP, think of it as a container. What needs to be in the container? What doesn't? If you turned your car into a program you could make an amateur mistake and make one huge object that controls every aspect of your engine operation. This would quickly equate to failure, as you would find it was so complicated and convoluted that you didn't know your blinkers from your spark plugs. Now (and this is greatly simplified of course) the better idea would probably be to make three primary classes. Intake, Combustion, and Exhaust. These would handle their departments seperately, but could easily be put together to make your car move. Now what about fuel management? This aspect is usually controlled by sensors installed in all three major elements of your cars engine. So why not make this functionality procedural, so it can be called from anywhere inside the other three objects, or outside of them if necessary? The biggest thing you would want to avoid is putting an exhaust related function in your intake class.

Quote:
Programming gets weird at this point, now that I no longer struggle to simply make something work, but I struggle to make it work in the best possible way... Thanks again
The makings of a good programmer right there. I've dealt with too many scripts written by 'experienced' programmers that make mistakes I made on day one, simply because they've never strived to improve performance (or their own understanding of what makes things tick).
delayedinsanity is offline  
Reply With Quote