What is Object Oriented Programming (OOP)

What is Object-Oriented Programming?

Object-Oriented Programming is a style of programming in which we write programs using objects and classes. These objects and classes indicate the data and the methods that are used in the program. We can create as many objects as we want for any single class. Now you may ask a question what is class and object? 

I know there are various questions that are stuck in your mind once you started programming especially when you began programming with OOP.

What is Object-oriented programming and its features?
What is OOPs concept?
What are the 4 basics of OOP?
Why we use Object-Oriented Programming?
What are the advantages of Object-oriented programming?
What are the differences between OOP and POP?

These are the issues that trouble the programmers a lot and when you are new in the field of programming and coding, it gets stuck with you. I also got annoyed by those questions. If so then don't bother you came to the right place.

You will come to know all the answers to the above-written questions. So, let's start encountering all the enemies and start with the very first question.

What is Object-Oriented Programming and its Features?

Object-oriented programming is a style of programming that gives a way of modularizing programs by creating a partitioned memory area. In Object-oriented programming, the data and functions are assigned some partition of memory.

We write computer programs in OOP by making use of objects and classes that denote the data and methods. In object-oriented programming, programs can be used as a template for creating copies of such modules on demand whenever the user needs it. 

It emphasizes on data rather than procedure. In OOP, Programs are decomposed into objects. The data are hidden in OOP and cannot be accessed by external functions. OOP follows a bottom-up approach. 

In other words, object-oriented programming is a way of implementation in which programs are designed as a cooperative collection of objects which represent some class. In order to solve any problem, the objects interact by transferring or sending messages and communicating with each other.

Pillars of Object-Oriented Programming or features of OOP

1. Class and Object.
2. Encapsulation.
3. Data Hiding.
4. Inheritance.
5. Polymorphism.
6. Message Passing.
7. Reusability.
8. Overloading.

Those are the main pillars and features of object-oriented programming methodology. Let us learn a little bit more about all those important features of object-oriented programming.

1. Class and Objects Classes and objects are the foundation of an object-oriented programming paradigm. Both are inter-related to each other. An object is expressed as an instance of a class.

An object is a real-world element. It may have some physical existence as well as some conceptual existence. The collection of similar types of objects is called a class. A class represents the collection of objects having the same characteristics and common behavior.

Whenever you create a class, the skeleton of the objects are created. Note that no memory is utilized whenever any class is created because creating a class simply means creating a template for the objects. Memory is only occupied upon the creation of objects.

Example: Class Declaration
class ClassName{
 Several Data

 ClassName Object1, Object2, ... ;

2. Encapsulation and Data hidingThe process of binding the methods with attributes in the class is called encapsulation. The internal details of a class can be hidden through encapsulation. Data are hidden by making the data private inside the class. 

Then it can only be accessed by the class in which it is determined. This is called data hiding. Combining data and functions together is Encapsulation. Data hiding is the process of hiding the data so that it cannot be accessed by outside. It insulates and hides the data inside a program. Data hiding is also called information hiding.

Example: Class and Object

class ClassName{
 datatype data;

 member functions;

 ClassName Object1, Object2, ...;

3. Inheritance - Inheritance is the property of classes to inherits from other classes that we called base or parent classes. 

Child class or subclass is the class which inherits the property of other class and the class whose property is inherited by base class is called parent class.

There are five types of inheritance. They are:
1. Single inheritance
2. Multiple inheritance
3. Multi-level inheritance
4. Hierarchical inheritance
5. Hybrid inheritance

When a child class is derived from a single-parent class is called single inheritance.
When a child class derived from more than one base class is called multiple inheritance.
When a child class is derived from a superclass and superclass is derived from another superclass and so on is called multi-level inheritance.
The tree structure like inheritance is known as hierarchical inheritance.
The combination of both multiple and multi-level inheritance is called hybrid inheritance.

4. Polymorphism - Poly means many and morphism means forms so the ability to take multiple forms is called polymorphism. Polymorphism is one of the main ideas in the object-oriented programming paradigm.

5. Message Passing - Objects in the object-oriented programming method may communicate with each other using message passing. 
Suppose there are two objects obj1 and object obj2 in a system. Then obj1 sends a message to obj2 asking for something and obj2 reply back. This is called message passing in OOP.

6. Reusability - When inheritance is possible then code reusability is also possible. When the child class inherits the properties of the parent class then it is the code reusability.
Reusability means using the previous code without changing the previous code but adding new stuff to it. It helps to decrease the number of lines of code and code size.

7. Overloading - Overloading simply means two or more methods having the same name with different arguments is called overloading.
When two or more methods have the same name but different arguments or parameters are called method overloadingIt is related to polymorphism.

What are the 4 basics of OOP?

The four main basics concept of OOP are:
1. Encapsulation.
2. Inheritance.
3. Polymorphism.
4. Abstraction.

Why we use Object-Oriented Programming?

Object-oriented programming gives us a new way of looking at any problem surrounding us to be solved by using a software. The programmer creates methods and functions to manipulate objects.

The main aim of OOP is to help us creating and finding more and more objects in any problems that we are going to solve using software. Procedure-oriented programming does not give real-world environments like objects and class that is why it is need of Object-oriented programming.

OOP gives us the power to model the world that helps us understanding better. If we look around us, there are objects and objects which are associated with them. For example, a chair is an object and a person who is sitting on the chair is also an object and both of them are associated when the person is sitting on the chair.

This is called the communicating of objects. In the same way, the programmers think of making something that will easier for them to relate to the real world. That's the reason for OOP coming into existence.

Advantages of OOP

1. It becomes easier for a programmer to model real-world objects by using OOP different pillars in programming.

2. With the help of inheritance, the programmer can make reuse of different classes by just inheriting. Inheritance saves a lot of time and also money.

3. The same operators may be used for different motives. This can be done with the help of polymorphism in OOP.

4. Larger and complex problems can be decomposed into smaller ones and even more smaller ones. It becomes easier to solve the problems. 

5. In OOP, there can be multiple classes of the same objects and that too without any interference from any one of the class.

Disadvantages of Object-Oriented Programming

1. Designing and implementation of its various concepts are complex.

2. Programs of Object-oriented programming are larger in size than that of the programs of procedure-oriented programming. The code may be complex and lengthy.

3. The speed of execution of object-oriented programming becomes slow because of its complex code.

4. The programmer needs to be intelligent and has a deep and clear knowledge of each and every OOPs concept. Extreme knowledge of programming and skills is required for programming in OOP.

Differences between OOP and POP

1. POP follows a top-down programming approach while OOP follows a bottom-up programming approach.

2. In POP, programs are divided into smaller ones which are called functions but entire programs are divided into objects in OOP.

3. There are no access specifiers in POP but public, private and protected access specifiers exist in OOP.

4. In POP, there is no concept of overloading but method overloading and function overloading do exist in OOP.

5. There is no concept of friend function in POP but it exists in OOP.

6. POP emphasizes on the algorithm but OOP emphasizes on the data.

7. POP is a structured-oriented or procedure-oriented paradigm while OOP is an object-oriented paradigm.

8. The main focus of POP is the structure of the program but the main feature of OOP is data security. 

9. POP does not support inheritance but OOP fully supports inheritance.

10. In POP, data hiding is somewhat not possible but OOP always secures the data.

Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.