Object oriented programming which is also known as OOPs is one of the most important concepts of programming. It is a programming paradigm which means a special way of writing programs.
It allows programmers to write modular code that is reusable, fast and well structured.
What Object Oriented Programming is actually?
OOPs is programming design in which a programmer defines custom classes from which multiples objects can be instantiated (created). The class encapsulates the methods, attributes and how the operations are performed on them, which allows programmers to focus on ‘what to do’ rather than ‘how to do’.
To simply the definition of OOPs we need to understand class and object.
A class may be defined as a blueprint for creating the objects. It defines all the properties like methods and attributes of the object, and how the object will behave and respond on certain actions.
The object is an instance of any class, it is generally the implementation of the class.
Object oriented programming is very helpful in solving large and complex problems because it is implemented by breaking the problem into subproblems. The efficient use of classes and objects provide a very convenient way to handle complex problems.
Apart from classes and objects, there are Four Pillers of Object oriented Programming which are also the building blocks of OOPs. They provide a lot more scope to optimize the code.
Real-Life Example :
Suppose we want to create a clay block, then we need to pour the clay in a bowl of particular shape and extract out when it solidifies.
Here, the bowl will be the class from which the clay block (object) is created. The class defines the essential properties of how the object will look like when they are created.
Programming Example :
Suppose we want to create an account inside a bank, we need a separate account for all customers. If we define each account code manually then it will violate DRY principle (Don’t Repeat yourself).
Here we will create an Account class which will contain necessary attributes and methods for its proper functioning and instantiate it individually for each new customer.
Advantages of Object Oriented Programming
OOPs, have a list of advantages for which it is preferred by the programmers. Some of the most important features of OOPs are :
Reusable Code: The classes are defined once and are used many times in the form of objects which saves lines of code and reuse the existing components.
Inheritance is a feature of Object-oriented programming which allows us to reuse the code of some other class into another class.
Structured Code: It provides a specific pattern for writing the code in terms of classes and objects.
It makes the code more readable and easy to debug.
Security: OOPs provide security to the code up to some extent. The variables and methods have access modifiers which define the scope from where they can be accessed.
Procedural Programming vs Object Oriented Programming
These two programming paradigms are the most popular ones and one of the hottest questions of programming interviews. It is necessary to know the differences between these two approaches to programming.
Procedural programming approach is older than OOPs and many languages like C, Pascal, COBOL etc. are procedural programming languages.
Both programming paradigm has its own advantages and disadvantages.
|Procedural Programming||Object Oriented Programming|
|Program is divided into functions.||Program is divided into classes and objects (they provide better structuring of code).|
|No access modifier.||Access Modifiers like public, private, protected etc. helps to define the right scope from where attributes and methods can be accessed.|
|It follows Top down approach.||It follows bottom-up approach.|
|Inheritance and overloading is not supported, so the code not that reusable as compared to OOPs.||Inheritance and overloading are supported which allows the programmer to reuse existing code.|
|Less secure as compared to OOP because no proper way of hiding data.||Secure because data can be hiddenusing access modifiers.|
|Example: C, COBOL, Pascal||Example: C++, Python, Java|
Apart from Object Oriented Programming paradigm and procedural programming, there are more in the list which you can explore here.