Abstraction in OOPS

Abstraction is one of the core concepts of Object-Oriented Programming. Abstraction defines a model to create an application component. The implementation of abstraction depends on the language-specific features and processes.

Abstraction in OPPS :

Objects are the building blocks of Object-Oriented Programming. An object contains some properties and methods. We can hide them from the outer world through access modifiers. We can provide access only for required functions and properties to the other programs. This is the general procedure to implement abstraction in OOPS.

Different Types of Abstraction :

There are tow types of Abstraction –

  1. Data Abstraction : When the object data is not visible to the outer world, it creates data abstraction. If needed, access to the Objects’ data is provided through some methods.
  2. Process Abstraction : When we hide the internal implementation of the different functions involved in a user operation, it creates process abstraction. Because we don’t need to provide details about all the functions of an object.

Advantages of Data Abstraction

  • Helps the user to avoid writing the low-level code
  • Avoids code duplication and increases reusability.
  • Can change the internal implementation of the class independently without affecting the user.
  • Helps to increase the security of an application or program as only important details are provided to the user.
  • It reduces the complexity as well as the redundancy of the code, therefore increasing the readability.

Abstraction in Real Life :

Abstraction is present in almost all the real life machines.

  • Your car is a great example of abstraction. You can start a car by turning the key or pressing the start button. You don’t need to know how the engine is getting started, what all components your car has. The car internal implementation and complex logic is completely hidden from the user.
  • We can heat our food in Microwave. We press some buttons to set the timer and type of food. Finally, we get a hot and delicious meal. The microwave internal details are hidden from us. We have been given access to the functionality in a very simple manner.

Abstraction vs Encapsulation

A lot of times programmers often confuse abstraction with encapsulation because in reality the two concepts are quite intertwined and share a relationship between them. Abstraction, as we’ve seen pertains to hiding underlying details and implementation in a program. Encapsulation, on the other hand, describes how abstraction occurs in a program.

Abstraction is a design-level process but encapsulation is an implementation process. Encapsulation tells us how exactly you can implement abstraction in the program. Abstraction pertains to only displaying the essential details to the user whereas encapsulation pertains to typing up all the data members and associated member functions into a single abstracted unit.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *