Object Oriented Programming vs Procedural Programming
Object Oriented Programming (OOP) and Procedural Programming are two programming paradigms. A programming paradigm is a fundamental style of computer programming, and they differ in the way different elements of the program are represented and how steps for solving problems are defined. As the name suggests, OOP focuses on representing problems using real-world objects and their behavior while, Procedural Programming deals with representing solutions to problems using procedures, which are collections of code that run in a specific order. There are programming languages that support key aspects of OOP (called OOP languages), Procedural (called Procedural languages) and both. But one important thing to note is that OOP and Procedural are two ways of representing problems to be solved, and it does not matter which language is used. In other words, OOP languages can be used for Procedural Programming while Procedural languages can sometimes be used for OOP, with some effort.
Procedural Programming is a way of programming by identifying the set of steps to solve a certain problem and the exact order that they should be executed to reach the desired outcome or state. For example, if you want to calculate the month-end closing balance for a bank account, then the required steps would be as follows. First, you acquire the starting balance of the account and then you reduce all the debit amounts occurred during the month. After that, you add all the credit amounts occurred during the month. At the end of the process, you will get the month-end closing balance of the account. One of the main concepts of Procedural Programming is the Procedure call. A procedure also known as a subroutine, method or a function contains an ordered list of instructions to be carried out. A procedure can be called at any time during the execution by any other procedure or by itself. Examples of Procedural programming languages are C and Pascal.
In OOP, the focus is on thinking about the problem to be solved in terms of real-world elements and representing the problem in terms of objects and their behavior. Object is a data structure that closely resembles some real-world object. Objects contain data fields and methods that represent attributes and behavior of real-world objects. There are several important OOP concepts such as Data abstraction, Encapsulation, Polymorphism, Messaging, Modularity and Inheritance. Some popular OOP languages are Java and C#. However, they can be used to perform Procedural Programming as well.
The key difference between OOP and Procedural Programming is that the focus of Procedural Programming is to break down the programming task in to a collection of variables and subroutines while, the focus of OOP is to break down the programming task in to objects, which encapsulate data and methods. Most notable difference could be that while Procedural Programming uses procedures to directly operate on data structures, OOP will bundle the data and methods together so that an object will operate on its own data. When it comes to the nomenclature, procedure, module, procedure call and variable in Procedural Programming are often referred to as method, object, message and attribute in OOP, respectively.
elango says
There
are 2 major software development approaches. They are listed below.
·
Procedure oriented approach
(structure oriented approach).
·
Object oriented approach
Procedure
oriented approach:
·
Procedure oriented approach always
concentrates on functions in the particular application, instead of considering
the entities involved in the application.
·
The software is fully based on the
functions.
·
C programming is a procedure
oriented programming language (POP).
·
Procedure oriented approach is not
suitable to create real world applications.
Example
for POP:
Let us assume, we going to create software for
banking domain. The application is related with money transfer. Now let us see
how we will develop the software using POP.
Scenario: First customers have to get the form and
should fill it and submit it to banker. Banker will receive and process the
application form. Once banker done with the money transfer, banker will inform
to manager stating the status of the money transfer. And manager will issue
acknowledgement to the customer and customer will receive it. Current system is
a manual process and we are creating application to overcome the problem in the
current system.
Step
01: Identify the functions in the application.
·
Start the application
·
Get the application form
·
Fill the form
·
Submit the form
·
Receive and process
·
Inform to manager
·
Issue acknowledgement
·
Receive the acknowledgement
·
Close the application
Step
02:
Identify the variables in the application.
Assume money transfer is one of the modules in
the application, so the application even consists of common information about
the customers.
Common
information’s about the customer: A/cno, name,
age, account_type, e-mailid , contactno, fathername, annual_income, signature ,
dob.
Note:
Even password credentials can also be stored in the application.
Variables
needed to complete the application process:
Toa/c_holderNo, to_branch, to_bank, to_amount,
application_date, etc.
Step
03:
In the application, all the functions are used
in the main function. Few variables will be declared as a global variable that
will be shared by the functions. And few variables are local to the function.
If we write coding for all the functions and place it in a proper way, then the
application works properly.
Limitations
in the above developed application using POP:
·
We are not giving importance to
the objects involved in the application. Objects involved are Customer, Banker
and Manager.
·
Variables which are declared
global can be accessed by any functions in the application. Even banker and
manager involved functions can also access personal information’s of the
customer which is declared global to the application. So security is
lacking.
·
In POP each function is depend on
each other, but this not the structure in the real world environment.
·
Any changes to the application is
not that much easy.
Note:
Customer
functions – get the form, fill the form, submit the
form, and receive the acknowledgement.
Banker
functions – receive and process, inform to manager.
Manager
function – issue acknowledgement.
Note:
To overcome the limitations in the POP
language, we just moved to the next level called object oriented programming
language.
Procedure
oriented language are used to develop small applications.
Object
oriented approach:
·
Object oriented approach always
concentrates on objects or entities involved in the application.
·
The software is fully based on
classes and objects.
·
C++ and JAVA is object oriented
programming language (OOP).
·
Object oriented approach is used
to create real world applications.
·
Object oriented approach provides
data security, overloading, inheritance, etc.
Developing the same application using OOP language:
Step 01: Identify
the Entities involved in the application.
·
Entities involved are Customer, Banker,
and Manager.
·
The basic concept involved in the OOP
language is CLASSES.
·
Classes in the particular application
are entities involved in the application.
·
So we need to declare 3 classes in the
application – Customer, Banker, and Manager.
Step 02: Place
the functions and variables in the classes.
·
Customer
class functions – get the form, fill the form,
submit the form, and receive the acknowledgement.
·
Banker
class functions – receive and process, inform to
manager.
·
Manager
class function – issue acknowledgement.
·
Customer
class variables – A/cno, name, age, account_type, e-mailid ,
contactno, fathername, annual_income, signature , dob, password credentials ,
Toa/c_holderNo, to_branch, to_bank, to_amount, application_date, etc.
·
Banker
class Variables – only a/cno, name, signature, Toa/c_holderNo,
to_branch, to_bank, to_amount, application_date are exposed to banker class to
process the application.
·
Manager class
variables –
Manager Class consist of variable Manager ID which is exposed only to banker class,
not to customer class. Only
a/cno, name and status of the application are exposed to the manager class to
acknowledge the customer.
Step 03: Final step. The objects of Customer, Banker and Manager Classes
are interacted with each other. This is the way the complete application is
designed in the object oriented programming language.
Advantages of OOP when compare to POP:
·
It is more suitable for real time
application development. It very close to the real world implementation.
·
Here we are giving importance to
the objects involved in the application. Rather than giving importance to the
functionality. Objects involved are Customer, Banker and Manager.
·
Variables are declared in the related
classes, and only the necessary information’s are exposed to the other classes.
So data security can be ensured.
·
In OOP each functions is not depend on each
other. The objects interact with each other using functions.
Modulo m says
Procedures do not have to be coupled. You are literally a dumb ass if you think that.