Featured image for The Power of Object-Oriented Programming: Building Maintainable Code

The Power of Object-Oriented Programming: Building Maintainable Code

Introduction

Once upon a time, programming was a mystic art! An art that could only be performed by the ones well versed in the way of computers. But this image of programming has long been changed. There are many tutorials out there both in texts and videos that make this art much easier to learn. One can learn any language and build their applications. But is that all? Or is there more to this than meets the eye?

The Story

You can now get started with building your app in any language. You settle on Python as it is a beginner-friendly language. You google “Python tutorial” select one of the top results and start learning the language. You are now ready and one step closer to building your app. During this journey, many errors are going to attack and prevent you from completing the app, but your Google-Fu is top-notch. Those puny errors will be of no match to you! After all the think, write, and debug cycles you have reached your goal. That app you wanted to build is now ready!

Now happy and excited, you show off your learnings to your peers. You get compliments and also some interesting feedbacks for additional features. Inspired by the well build apps from big companies such as Microsoft, Google and Adobe, you decide to improve your app. You get to work and start writing code to add all those cool features your friends suggested. But wait! Now you are facing a different kind of problem. Your codebase is now a whopping 200 lines long, and now you’re finding it difficult to add new code. The errors are now much more frequent with functionalities breaking on adding new code. Being frustrated, you decide to take a few days of break.

Now with a fresh spirit and mind, you decide to complete your app. You start scanning through your code to reach the point where you left off. But to your horror, you are now facing difficulties understanding your own code. Still undeterred, you push yourself for a couple of hours. To your dismay, you are still facing the same trouble as before. You lose all your motivation and finally decide to quit.

So what happened? What went wrong?

The Analysis

What you are experiencing is a classic problem of poor code structuring. This leads to low maintainability and makes it very hard to add new code. This is common in many beginner’s projects where the main focus is on functionality. So how do we write code which is not only functional but also easily maintainable and extendable?

The Solution

The term “Object-Oriented Programming (OOP)” was coined by Alan Kay at grad school in 1966 or 1967. It took off in the software industry, replacing the largely prevalent procedural programming paradigm.

The advantages of using this new paradigm are,

  • It improves simplicity, as the software objects are analogous to the real-world objects. It brings down the program’s complexity by providing an intuitive idea about the structure.
  • It encourages modularity, as each object is a separate entity that is decoupled from each other.
  • It improves extensibility, as OOP has the concept of classes and inheritance where a class can extend upon the functionality of another class.
  • It increases modifiability, as we can change the internal implementation of class methods which would not affect other classes provided we don’t change the public interface. The internal implementations of objects are abstracted away from each other.
  • It improves maintainability, as classes are self-contained they can be maintained separately. This makes locating and fixing errors easier.
  • It encourages reusability, as we can instantiate a class anywhere and any number of times.

So following the OOP paradigm, we can easily resolve our code extensibility and maintainability issues. But hold on! how do we learn about it?

The Path

The OOP paradigm is a vast field with many programming languages that have slightly different implementations of it. But there are some core concepts that one needs to learn first to grasp it.

  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

I believe in the philosophy of Learn by Doing, where you learn about something by getting hands-on with it. I have recently completed some exercises at Crio.Do on the said concepts. Solving a real-world based problem using the learned concepts goes a long way by solidifying the intuition and the concept together.

Conclusion

At the beginning of every programmer’s life, their first major project is a structural mess. Learning the basic OOPS concepts helps to introduce a structure to the code. But this is just the beginning of the journey. There are more stuff to learn like SOLID and GRASP principles and so on. This journey is a continuous evolution and has no real end. As the applications scale and the requirements change, there might arise a need for a new structure in the future. So staying updated is a crucial job for a developer in this ever-changing field of IT.

So good luck with your journey! And thanks for taking the time to read my article.

OOP
Encapsulation
Abstraction
Inheritance
Polymorphism
© 2023 Arunangshu Biswas