Confused About Objects...
View Single Post
01-23-2010, 11:06 PM
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
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.
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).
View Public Profile
Send a private message to delayedinsanity
Visit delayedinsanity's homepage!
Find More Posts by delayedinsanity