Software Development Basics – Object-Oriented Programming

Life is complex. Developing software is complex. When creating software that models life, a paradigm is needed to break that complexity down into something that we can comprehend and that can eventually be implemented into a computer program. Object-oriented programming or OOP is one of the best known and most practiced paradigms available.

There are four main tenets or concepts that serve as pillars for object-oriented programming.

  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. Polymorphism

Each of these concepts deserves its own post. Entire libraries of books have been written about OOP and trying to do it justice in a single post is absurd. However, explaining these concepts very plainly is possible without a lot of detail.

Introduction

It is important to know that OOP is language agnostic and will apply to any object-oriented programming language. The list of languages that are object-oriented is vast. It would be much easier to determine which languages are not object-oriented. It is also very important to note that languages that were not originally object-oriented such as PHP and JavaScript have moved toward supporting the object-oriented paradigm. This is important for a couple of reasons.

First, a language that fails to evolve will eventually fade away into obscurity. Ask Cobol about obscurity. 50 years ago, Cobol was an incredibly popular language. There are still tens of thousands of applications written in Cobol that are actively maintained at great expense. Today, very, very few businesses are creating new software in Cobol. It is a bad situation. Companies have to invest in keeping the legacy software running but that investment isn’t paving the way for the future. Typically, the same programmers maintaining Cobol don’t also know Java or C#. It happens but not often.

Second, it tells us that the object-oriented paradigm is making progress. It is extremely popular. You will see plenty of articles and books discussing OOP. More importantly, you will find many programs using the paradigm.

What is Object-Oriented Programming?

OOP is the act of modeling real-life objects. Real-life objects can be anything. It can be physical things like a car, house, book, person, or tree. It can also be conceptual things like an account, sale, idea, or lawsuit. Literally, anything in life can be modeled. In OOP, these objects and the data that makes up these objects are given real importance.

Classes are the basic building blocks of OOP. Not all classes are objects but all objects are classes. Classes are the building blocks of OOP. Objects are classes with state in the form of properties or attributes, and behavior. For this post and many other examples on the Internet, we will use vehicles in this example.

Encapsulation

Encapsulation is the act of hiding or protecting data or methods of an object. In the vehicle example, the speed of the vehicle could be a private variable. Methods like Stop and Go would effect the speed and might be the only way to modify the speed value.

Abstraction

Abstraction is the process of hiding details about the implementation of an object. Let’s go back to the Go method. In order to use that method, you don’t need to know or understand all that is going on behind the scenes of the Go method. That is because the implementation details have been abstracted away from consumers.

As you might have already noticed, abstraction and encapsulation are very closely related.

Inheritance

Inheritance allows us to have multiple vehicle types such as car and bus. Imagine all the differences between a car and bus. There are many. They both have engines, tires, models, manufacturers, and dozens of other small things. However, there are also many similarities. Inheritance allows us to have a hierarchy of objects that trace back to a single parent and each child ‘inherits’ the properties and methods on the parent and adds their own properties and methods. This hierarchy is inheritance.

Polymorphism

Polymorphism is related to Inheritance. Polymorphism allows child objects to keep parent attributes and define their own. This takes two shapes. Let’s assume that the Go method in the base vehicle class is a simple implementation. The vehicle’s Go method might be exactly the same for some versions of the vehicle such as a car and a bus but the Go method might look very, very different for a plane. In fact, a plane’s Go method might be to actually call a private method named Fly. This is polymorphism. Polymorphism actually means many forms and you can probably see why. There is a caveat, however. This is truly a simplistic explanation of polymorphism but it should give you a basic understanding of the concept.

Conclusion

Hopefully this post will give you a basic understanding of object-oriented programming, especially if you haven’t seen it or tried to understand it before. I will review each of the four pillars in greater depth later on.

Leave a Reply

Your email address will not be published.