What is Object-Oriented Programming? Pros & Cons?

Inheritance

You don’t need to be overwhelmed by the new concept of programming, which is Object-Oriented Programming.

OOP is being used by most of the programmers in the industry, minimising the chances of getting a job as a developer for anyone who doesn’t know Object-Oriented programming.

However, it is not that complicated to learn OOP in-depth, if you have an effective and well-structured syllabus or things to cover in your mindset.

We will discuss everything you need to know about the OOP. You might not become an OOP developer, but you will be on the path to becoming one after reading this article. Let’s dive into it.

What is Object Oriented Programming?

Object-oriented programming can be defined as a programming model that consists of classes & objects, methods, and attributes. It is the most prominent programming model used among developers. 

  • Classes can have attributes and methods.
  • Objects are the instances used to use attributes and methods of a class.
  • Attributes are the characteristics of the class. E.g, a class car would have attributes like tires and colours etc.
  • Methods are the behaviour of the class. E.g, a car class can have a method (Behaviour) like accelerate. When someone presses Accelerator, it would accelerate, this is will be its behaviour.

Classes & objects are the main features of oop. Objects are instances that can use the methods and attributes of the class. For instance, a class could be a car and its object would be Audi and Mercedes, etc. There will be behaviour and attributes that Audi and Mercedes can use from class instead of making their own each time from scratch, which will take time and effort as well as money. 

Below is an image explaining the concept of classes and objects.

What is Object Oriented Programming?

These features of OOP stand on 4 pillars, which are considered to be 4 Pillars of OOP. These are Encapsulation, Inheritance, Abstraction, and Polymorphism.

In short summary, the OOP definition would be “It is a programming model that provides structured and logical elements to the program”, which has many benefits. 

List of OOP programming languages

These are some of the most dominant OOP programming languages. 

  • C++
  • Java
  • Kotlin
  • Python
  • Swift
  • TypeScript 
  • and the list goes on…

4 Pillars of OOP 

These are 4 OOP principles that are the reason for Object-oriented programming being unique for programmers.

Encapsulation

Encapsulation means hiding important data and only showing specific information to the outside world. Encapsulation is used inside a class that defines whether the data is publicly or privately held. Encapsulation is used by having access modifiers. There are three access modifiers: Private, Protected, and Public. 

Private: Restrictive access modifier that does not allow the users or sub-classes to access the data.

Public: Everyone can access all the information in the class. 

Protected: All the subclasses can access or override the data in the class. However, the outside world can’t do it.

We use the Private access modifier to hide the important data, meaning that no one other than the developer can access the important information in the class. 

For instance, users could withdraw money, add deposits, and check balance options in their own accounts in the bank program. However, they wouldn’t be able to see the balance of the whole bank or any other main data. This specific feature of OOP mainly provides security.

Inheritance

Inheritance is when you can reuse the code. In the inheritance, a sub-classes can use all the attributes and methods of the main class with additional functionalities added.

For example, if there is a car class. Car class would have the typical features and functionalities of a car. But, there could be certain cars that have more than the typical features & functionalities such as sports mode, additional sensors and more sophisticated dashboard. Instead of going back to the main class and making changes to the main car class, which might be convenient for you. Because, that’s what you want in this specific car model. However, it wouldn’t be suitable for other car models. Because, not every car would have sports mode, additional sensors, cameras and advanced dashboard. 

So, you will use Inheritance to inherit the features and behaviour of the main class and add additional attributes and behaviour to it, this second class would be known as sub-class.

Inheritance

You can see that the Sub-Class has the behaviour of the main class. But, there are more things to it. The dashboard() has become Advan_dashboard, meaning that new functionality has been added. Inheritance provides the ability to reuse the code, condensing your code, making it more efficient and understandable. 

Abstraction

Abstraction is when the user is only able to access the chosen attributes and behaviour of an object. It allows the user to use a simple and easy to use tool to access a complex task. 

For example, if someone is driving a car, they will have a few tools such as an accelerator, brake, steer and clutch gear change etc. A driver doesn’t need to be an automobile engineer to drive a car, a driver doesn’t need to know the engineering when he presses a brake. Because it is a simple tool that is used to access complex behaviour of the car, which is to brake. 

This is an abstraction. When all the unnecessary information is hidden from the user. So the user is not distracted by the excessive data. Basically, making users’ lives easy.

Polymorphism

Object Oriented Programming provides the reusability of the code. Mainly, it’s the Inheritance that provides us with this privilege of overriding a method to have different behaviours in the child class. Polymorphism also entitles us to reuse our code by either overriding or overloading the method. 

Method Overriding means overriding a method in the child class to behave in a certain way. Meanwhile, method overloading is to have two methods that are made with the same name and different parameters. They behave accordingly depending on what parameters have been passed.

Advantages of Object-Oriented Programming

These are some of the pros of Object-Oriented programming:

Reusability – OOP provides the ability to reuse the code through its pillars such as Inheritance and Polymorphism.

▸Excellent Problem solving – One of the main objectives of any programming language is to solve problems. OOP comes with an effective method of solving problems by breaking them down into little parts and solving them. OOP code structure also helps programmers solve problems easily. 

▸Increased efficiency – When the programmers have well-structured code that has been broken down into little parts and also has the entitlement to reuse the code, which increases the overall efficiency.

▸Excellent Software Improvements – Object Oriented Programming provides an excellent level of scalability in the programs, improving the final software product.

Disadvantages of Object-Oriented Programming

▸Big Program Size – OOP code tends to be longer than other types of programming such as procedural programming language.

▸Experts needed – OOP languages are very hard as compared to other programming languages. Developers need to be quite expert to be able to avail all the advantages of OOP. Otherwise, they would end up having all the disadvantages of OOP.

▸Too much Effort required – Object Oriented Programming might suit many. However, it isn’t suitable for small or sometimes medium size programs. There is just too much effort that goes in while programming OOP, designing and making classes and objects etc. Whereas, the same thing can be easily done in other programming languages. 

Final Thoughts

These were a few key points regarding Object Oriented Programming. It is widely used for a number of reasons in today’s programming world. However, it doesn’t mean that other types of programming languages are dead.

3 thoughts on “What is Object-Oriented Programming? Pros & Cons?”

  1. Pingback: 5 Best Tips to Learn C++ Programming - mycodings

  2. Pingback: Is Programming the future? Types of Programming? - mycodings

  3. Pingback: Differences between C++ vs Python

Comments are closed.