Importance of learning Object Oriented concepts

Solving complex problems is all about well defined thinking and organization. The better organized your code is the more complex problems you can solve, both with more accuracy and in less time. Take an example of a library. It’s well organized into different sections. Each section has many racks and each rack has many shelves. The books are organized in such a manner that it never takes more than 5 to 10 minutes to find a book in the library. Now think if all the books in the library were just kept in a sequence in which they were purchased, without any logical organization. You can well imagine that in this case you will not be able to find books easily. You will waste hours and hours searching for books because they are not arranged logically.

Let’s take another example. Let’s say that you start a small company to sell books with just 2 employees and you have a small office. All the tasks important to run the company are performed by you and your 2 employees. There is no well defined separation of work between your employees. You ask them to do various type of work depending on their availability. Also all the files related to the company finances, sale and purchase, daily expenses etc are kept together in a small cupboard. Because you have a small company and the work load is not too much you can manage things without much organization.

The above example is the same as procedural programming. In procedural programming you do not organize your data and code much. The focus of procedural programming is on getting the work done. The whole program is like a very lengthy piece of code , sometimes divided into small functions which you call to do specific tasks. Procedural programming revolves around functions. Procedural programming is good when the problems which you have to solve are relatively simple in nature and need less lines of code. But as the problems become more complex you need better organization of code.

Now moving forward let’s say that your company has now grown and you have 100 employees in your company. The work load has increased to an extent that without proper organization it is impossible to handle the work properly. What will you do now ? You will try to organize everything in your company, from employees to your files. The easiest way to do is to divide the company into various departments. Each department will have its own team of people specialized in handling their own work. You will have a department for handling finance related issues, a separate department to handle purchase of books, a separate department to handle sales. Also you will have to create a new HR department to handle issues related with your employees. Each department will have two things in common – people and files. Why do we need files? To store data and information because people cannot keep that much data inside their heads. Why do we need people ? Because files cannot go out and do work. We need people to go out and do work. So basically the problem is about two things – managing data and work. In terms of programming you say that the problem is about managing data and functions ( work ).

Now there are a few logically questions you need to ask

First question – Do you want the people of the HR department to have access to the files from the accounts department ?

The answer will be no. Why? Because if you give everybody access to all files from all departments and if some files go missing from your office whom will you hold responsible? No body!! This is because when everybody does everything then nobody takes the responsibility.

In terms of object oriented programming we say that the data of one object should not be accessible to the other object. This way each object can make sure that its data is correct and no outside object will be able to use it without its permissions.

Second question – Can you ask the person from the sales department to take care of accounting?

The answer is no. Why? Because accounting is a job which needs special skills and experience and you cannot just ask anybody to do it for you. In terms of object oriented programming we say that we divide the complete logic of the program into their respective objects. Each object takes care of doing it own work. If you have a file reading and printing application then it will have two objects, one object to read files and the other object to handle the printing. Object oriented programming helps us in dividing related functions into proper objects just like in the office you put people with different skills into different departments.

Third question – You have a new employee in your company. You want him to be introduced to everybody in the company and also want his bank account to be opened at the earliest. Now as the head of the company how will you get both these things done?

Answer

You will have to take the help of two departments - HR department and Accounts department. You will pick up the phone and call the HR department and ask them to introduce this new employee to everybody in the company. Next you will pick up your phone and call the accounts department and tell them to get a new bank account for this employee.

In object oriented terminology we will say that you have two different objects in your program – HR and accounts. When you have to get the new employee introduced with everybody you will call the function of the HR object. When you have to get a new bank account for this employee you will call the function of the Accounts object.

The whole object oriented philosophy revolves around objects. You divide a big problem into smaller objects. Each object is capable to handling its own data ( files ) and performing its own functions. When you have to get some work done from an object you call their function and get the work done.

Conclusion

  1. Procedural programming revolves around functions where as object oriented programming revolves around objects.
  2. Object oriented programming is about better organization of functions and data using objects.
  3. In object oriented programming you have better control over data and well defined roles for each objects.
  4. When you need to get some work done you know which object can do this work and you call the respective function of that object.
  5. It is difficult to handle large applications with procedural programming. Object oriented programming helps you in better structuring of your application and therefore you can handle complex applications easily.

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp