Free Consultation? Call Us At (678) 200-2497

Real World Applications of Object Oriented Programming


Object oriented programming (OOP) is a big deal in today’s technological world. Without it, I think software in general would be much less stable. So what is it and how can we benefit from it in our daily lives?

First let’s talk briefly about the pillars of object oriented programming. They are polymorphism, inheritance, and encapsulation. So let’s dive into each one a bit more, but not too deep. Inheritance is an important and fairly simple concept. An object is derived from another object which means it contains all the same things as the parent, but these variables and functions do not need to be explicitly stated. So in the real world, we can think of a person giving birth. The baby inherits certain properties from the parents. Might inherit their looks, definitely their DNA and so on. So as the baby is created (or as a derived object is created) certain things that come from the parent (inherited) can be accessed from the parent part of the child. So in computer terms the parent is within the child and the child inherits from the parent so when we need an attribute that comes from the parent that was not explicitly stated as a child attribute, we access the parent portion within the child object to obtain the attribute.

Polymorphism .. another pillar of object oriented programming is the ability to treat objects and their derivations in a like manner. So let’s use the typical employee example. Employees at a company can be regular employees that fulfill the business mission, managers, and executive level. In a company hierarchy some positions have more weight for their opinion than others, however they are still all employees. In other words, they are all human, so they have a name, social security, salary and so on. 



Polymorphism is taking the concept of treating them in like manner to a function. So in the real world let’s assume these employees want to get a gym membership. So the gym has a function called new_member. And they want to know the pay for the person. If a normal employee fills out the form, they will calculate their hourly pay to convert to a salary. If a manager fills out the form, they may use their salary plus their bonus, and if an executive level employee fills it out, they may use their salary, bonuses, stock options and so forth to calculate their pay. But the gym doesn’t care who they are, just that they can calculate their pay so register will accept an employee or any derived class from it and when calculate pay is called within the function, based on what was passed to the function, the object will calculate its pay. This is done with the use of virtual functions in C++ and similar concepts in other languages. See below.

//pseudocode
function new_member(Employee *)
-------------------------------
Manager derived from Employee
Exec derived from Employee
-------------------------------
myManager = new Manager
myExec = new Exec
myEmployee = new Employee
-------------------------------
//polymorphism
new_member(myManager) //calls Manager->getPay
new_member(myExec) //calls Exec->getPay
new_member(myEmployee) //calls Employee->getPay

Finally encapsulation. Encapsulation is in essence security for an object. The only way to change the state of the object is to use the public functions that allow you to make changes to the objects. These public functions can enforce business rules and encapsulate how the object is changed or manipulated.

And we also have the concept of containment. So an object has or contains another object. Each object has the pillars of OOP, but as in the real world, we can hold other objects, so containment is the way that an object holds or contains another object.



With these concepts in mind, let look at a real life application of OOP. When I started to truly understand these concepts, I thought to myself, wow, this stuff is pretty cool. As I realized we were just imitating the real world, I asked, well can I get good at programming then apply that to the real world. This is the reverse of thinking about a real world example then trying to understand why the programming construct came about.

So what did I come up with? For containment especially, as a younger man, I used to go to the gym with my gym bag, then I had my access card somewhere in my car and my gym lock also somewhere in my car. In many cases, I’d take my gym bag and forget either my access card or the lock for the locker causing a return to the car. After truly understanding containment and applying it, I thought to myself. Hmm, let’s have a gym bag as an object, and it contains the gym lock object and also contains the access card object. 

Well that’s pretty easy to do in real life. Needless to say, I’ve never forgotten my access card or gym lock as long as I have my gym bag for a gym workout 🙂 . You can apply these same things also when you learn architect skills in OOP. When you architect with solid foundational software engineering principles, it may be a good idea to step back and see if your solutions can also help your real world .. after all, we program reality for the most part, not the other way around.

This of course is a two way street. Of course, we use the wash and dry clothes example. Most people don’t wash the colors, dry the colors, then wash the whites dry the whites. People program like this all of the time. What most people do is wash the colors, dry the colors and wash the whites at the same time, and then dry the whites. This is more time efficient, but how do we program this? So we hash out the ideas from the real world to programming and back to the real world. If you do this, it can certainly improve your life as I find it to be priceless. Think about sorting algorithms .. applying that to real life after learning the technique and such. Anyways, the applications are infinite when you think healthily as a programmer.

Have you had any real life applications that came about because of how you implemented an OOP project? Have you had a similar aha moment to the gym bag story that improved your life instantly? Let us know below!


jimi author

By jimi

Jimi is an expert software architect and photographer. He enjoys taking on new challenges and learning as much as possible during each challenge. He also enjoys swimming, biking, and hiking.

Would You Like To Share Your Thoughts?

Your email address will not be published. Required fields are marked *

Mobile version: Disabled