
This is the first part in a mini series on building a solid foundation of principles and practices that will enable you to write better code.
Object Oriented Programming is going to be the foundation of everything we talk about from here on out. OOP provides huge power and flexibility later on down the line when we discuss techniques to help in the maintainability of our code.
As a side note, you will find that I tote maintainability as a hugely important factor. To me, maintenence is the biggest comsumption of development resources whether it be through bug fixes or adding new features. Anything that can make code easier to maintain long term is, in my book, worth exploring.
I am well aware that OOP has had some strong opposition and criticism including Richard Stallman (see his comments). Perhaps OOP is not for everyone but it has great value to me.
If you feel that OOP is not necessary or is a waste of time then I present to you two options:
- Stop reading this series and continue to ignore an opportunity that might improve your coding skills
- Reevaluate your opinon of OOP by reading the Wikipedia page linked above. Then continue this series.
Why Object Oriented Programming?
There are a lot of reasons to use Object Oriented Programming.
- Code resuse. I try and follow the princliple of Don’t Repeat Yourself (DRY) as much as possible. OOP helps by easily allowing you to create reuseable components
- Extensibility. When you can easily implement or extend your classes it makes your code more flexible and robust.
- Maintenence. When your code is modeled after real life objects and concepts and your code is flexible it is easier to maintain. There is nothing worse than trying to make changes to poorly designed code.
The thing I like most about OOP is the ability to mimic the business objects in code as they are in real life. To me this makes the code far more readable and easier to maintain. Let’s look at a simple example (I am using C#).
public class Pet {
private string name;
private string species;
private string favoriteFood;
public Pet(string name, string species, string favoriteFood) {
this.name = name;
this.species = species;
this.favoriteFood = favoriteFood;
}
public string Name {
get { return name; }
}
public string Species {
get { return species; }
}
public string FavoriteFood {
get { return favoriteFood; }
}
public virtual string Speak() {
return "My name is " + this.name;
}
}
The above code, being modeled after a real life object, a pet, is easy to understand and should be intuitive as to it’s use. Another great thing about our above class is that we can easily inherit from it to create a similar, yet more specific, class.
public class Cat : Pet {
public Cat(string name) : base(name, "cat", "mice") {
}
public override string Speak() {
return "meow";
}
}
See how easy that was? If in the future our program requires all Pets to have new features we just update out Pet class and all classes that inherit from Pet get the new features as well. If you haven’t guessed I like things with low maintenence costs.
That’s about it. I know I didn’t go into a lot of detail explaining all the aspects of OOP. That is just to much for this post. It could easily be a lengthy series of it’s own. I would strongly encourage you to do some reading on OOP if you need to know more.
Did You Enjoy This Post?
Be sure to grab my RSS feed so you don't miss out on more great articles.
This Post Was Brought To You By
How do I save time? I use FreshBooks for invoicing.
Get Information Technology magazine subscriptions and white papers for FREE!
Object Oriented Programming Is Your Foundation

Did you like this post? Be sure to

July 30th, 2008 at 2:57 am
Agreed. OOP is the foundation now. I’m even surprised by this post, because it seems to be really obvious.
As for Mr Stallman, he seems to be have been a critic of everything for the last 20-30 years, but I cannot name a product made by him… So, who really cares ;-)?!
July 30th, 2008 at 4:11 am
Well, I would have thought it was painfully obvious that the world uses OOP but our company recently hired a programmer, though writes very good OOP code, admits he thinks it is a waste of time and doesn’t see how it is better than procedural programming. Then again, he has been living in UNIX only and PERL for the last 10 years until getting hired by us (a .Net shop, don’t ask…I don’t do the hiring :D)
July 30th, 2008 at 8:58 am
[…] Part 1 - Object Oriented Programming Is Your Foundation […]
August 14th, 2008 at 6:52 am
When i discovered OOP, I felt like I was cheating. Complex problems I was afraid to tackle became obvious OOP implementations. Procedural programming might as well be programming without functions or sub routines. Seems more like the natural extension of programming to me. Next is true parallel programming, although it seems like the rambunctious implementations of JS library(plugins, lol) architecture look like the perfect paradigm with which to model such programming structures.
August 14th, 2008 at 9:44 am
I have heard people argue that they get no benefit from using OOP. I think they aren’t implementing it correctly or are working on smaller projects where OOP may not be necessary.
I always find OOP simplifies large projects.