I just can’t stay away from this stuff. I told myself that I would convert this into a personal blog, but that I would try and keep the coding and such out of it. It would be a day-to-day account of my life. But damn. My life can get boring some days you know? Who want’s to read about me sitting around in my snuggie (just a snuggie) and reading for 6 hours? No one. That’s who. And old people I guess.. things like that would probably be exciting reading to them. And stalkers. But I’m sure I don’t have any of those. And even if I did, they’d probably already know that stuff.
Anyways, what I’m actually talking about today is Object Oriented Programming. To many it’s a very confusing concept and they’re flooded with questions such as when to use it, why would I use it, what IS it? And to others it comes as easy as breathing.
*NOTE* OOP is a slightly advanced concept. While you should try and learn it as soon as possible, you should have at least a moderate grasp of classes and functions.
What is it?
OOP is a way of programming that breaks down an object into pieces. Essentially an object would be something that you’re trying to achieve. OOP breaks this down so that you don’t have to continually write the same code. Instead, you can just copy over the class file, and then use the same functions as you normally would. That is the bonus of OOP.
To think of it another way, imagine a robot. That robot is what we are trying to build. But a robot is made of different pieces right? 2 arms, 2 feet, a body and a head. In Object Oriented Programming, you would take each piece and make it it’s own class.
How does it work?
What we would essentially do now, is populate this class with things that the arm can do. In this example, lets just make it very simple. All the arm can do is Judo chop and Punch. To accomplish this, all we would need to do is create two functions within our class. However, note that I said we have TWO arms. We would need some way of differentiating the right arm from the left right? The easiest way to do this, is to create a “constructor” function that would accept the name of the arm and store it for access later on.
name = $name; } function punch() { echo $this->name.' punches'; } function chop() { echo $this->name.' judo chops'; } } ?>
From that piece of code alone, we can actually create as many arms as we need. And that is the beauty of OOP. Now my robot can run on the same piece of code, regardless if it has 2 arms, or 50 arms. Imagine, an awesome 50 armed robot running off no extra code?
When would you use it?
As often as it makes sense. If you’re building any application, your best bet would be OOP. However, if you’re working on something like a website, there really isn’t a need for it. You’ll find people from all over the internet who say that you should use OOP all the time, and others who claim that it is the worst thing to happen to programming. Ignore them. In the end, it’s up to you to decide when you need to use OOP. If you find that you seem to be using a same bit of code all the time, wrap it in a function. If you find a group of functions you use all the time, and they’re related, wrap it in a class. If you have a group of classes you use all the time, wrap it in a framework.



Aside from the computer I play a lot of guitar. I’ve been playing for almost 6 years now and am starting to actually get kind of decent at it. Maybe if I feel like it, and I actually get a good microphone, I’ll record some stuff one day. Most of the music that I play is actually metal.. pretty hard-core metal. I listen to a lot of bands ranging from Metallica (on the softside) to Emperor and Arch Enemy. More recently I’ve been getting into a really under-rated band called Protest the Hero. These guys are Canadian, and they’re incredible. Some of the most technical guitarwork that I’ve seen, and I don’t believe that the guitarists have been playing too long. My own musical writing style seems to be fairly fluid, allowing me to shift from black metal, with it’s speedy trem picking screeches to full on melodic death metal.