Procedural Programming Paradigm

PrevNextBack

Procedural Programming Paradigm

In this video, we will go through an example to better understand Procedural Programming and its challenges and how Object-Oriented approach helps in overcoming some of these challenges. This will help you to better appreciate Object-Oriented paradigm.

Assume that you are an instructor at one of the workshops in a conference. In a conference, people move from one class to other class depending upon their interests and agenda. So the attendees of your class also have to attend another class after your class finishes but they don't know the location of their next class. One of your responsibilities is to make sure everyone knows how to get to their next class. In Procedural paradigm your solution to this problem will be something like this:

  1. You will get a list of all the people in your class
  2. For each person on this list:
    1. You will find the next class they are taking
    2. Once you know the class, you will find where that next class is located
  3. Then you will try to figure out the way from your class to the person's next class.
  4. Once you know the path, you will explain to each person individually how to get to their next class.

Sounds like a lot of work, isn't it. Lets analyze this solution and see whether we can do this more efficiently.

Limitations of Procedural Programming

In software world, the only constant is change. Software is always evolving and the piece of code you have written today needs to be enhanced tomorrow due to new and changing requirements. Turns out, Procedural paradigm is not very good and robust in adapting to change. Lets see what happens when some new requirements come in for our conference example. Suppose among the attendees there are also a few volunteers who are assisting you. You need to give special instructions to the volunteers to collect the filled up feedback forms from the attendees and submit them at conference office before proceeding to their next class. In order to do this, you will have to change your program to distinguish the volunteers from the regular attendees and then give special instructions to the volunteers. This amounts to making significant changes which impacts the entire program itself. Just imagine how difficult it is to make changes to a software which is following procedural approach and has thousands of lines of code.

A more practical approach for this problem can be that you will post instructions to get to all the other classrooms from your classroom at the back of the room. The attendees know which classroom they need to go to next. You will ask them to refer to the instructions and figure out how to get to their next class.

Advantages of the new approach

In the first approach where you were giving explicit directions to everyone, no one other than you is responsible for anything. You have to pay attention to a lot of details and there is a very good chance that you may go crazy. In the second approach, you have given general instructions, each person is responsible for themselves to figure out the right instruction for them. You shifted some of the responsibility from yourself and made the attendees responsible for their own behavior.
With this approach, handling the requirement of giving special instructions to volunteers is more manageable. You will say that here are some special instructions that volunteers need to follow. Each attendee knows if he is a volunteer or not. If he is a volunteer he will start following the special instructions otherwise ignore them. Now the changes are only limited to the volunteers, the rest of the solution is not impacted at all.

With this second approach, we have just started to touch upon Object Oriented Programming. Don't worry if some of the things in this explanation didn't make a lot of sense to you. Over the course of next few videos we will look at it more closely to understand it better and by the end of the course I am very confident that you will become a master at Object Oriented Programming using Java.