Abstraction in OOP simply means the concept of OOP that shows only essential or needed attributes and hides unnecessary information.
Table of Contents
S.N | Contents |
1. | What is OOP? |
2. | Abstraction in OOP |
3. | Example of Abstraction in Real Life Example of Abstraction in OOP Types of Abstraction in OOP Abstract Class and Methods Why use Abstraction? |
What is OOP?
OOP or Object Oriented Programming is anefficient, reusable method of programming. As the name suggests, it targets the specific data, or objectthat the developer wants to manipulate rather than the logic behind them. An object means the data fieldthat has unique attributes and behavior. This is more suitable for large and complex programs as well ascollaborative development where projects are divided into groups.
"Simula" is said to be the first object-oriented programminglanguage but many other programming languages are used with OOP today. Some programming languages treateverything as objects so they pair better with OOP and are called "pure OOP languages". For example,
- Ruby
- Scala
- JADE
- Emerald
While other programming languages are also primarily designed forOOP, they include some procedural processes. For example,
- Java
- Python
- C++
- Dart
Abstraction in OOP
In OOP, programs are mostly very large and maintaining such hugecodebase for years is very difficult. Abstraction is a concept aiming to ease this problem. There are 4principles or pillars of OOP and Abstraction if one of them. Abstraction in OOP simply means the concept ofOOP that "shows" only essential or needed attributes and "hides" unnecessary information. The main purposeof Abstraction in OOP is to select data from a larger pool to show only relevant details while hiding theremaining data. This is one of the most important principle of OOP as it helps in reducing programmingcomplexities and efforts. The other pillars or principles of OOP, in case you are wondering are:
- Encapsulation
- Inheritance
- Polymorphism
Example of Abstraction in Real Life
Abstraction is present in almost all the real life machines. Forexample,
- Microwave
We can heat our food in Microwave just with press ofsome buttons. What happens inside after we press the buttons? All those details are hidden fromus and we don't need to know them to use the microwave.
- Your Phone
You can use your phone with just a few buttons andinputs but, what happens after you press the buttons? You don't have to know that to use thephone.
Example of Abstraction in OOP
As mentioned earlier, objects are manipulated in OOP and can becalled the building blocks of Object-Oriented Programming (OOP). An object contains properties and methods. We can choose to show or hide those properties to the outer world with Abstraction.
Types of Abstraction in OOP
1. Data Abstraction
To ease the interaction with the database, thedevelopers hide internal irrelevant details from the users which is called data abstraction. Or,it can be defined as the reduction of a particular body of data to a simplified version torepresent the whole data.
2. Process Abstraction
Many functions are used in creation of a program.Process Abstraction means hiding the internal implementation of functions from the user.
Abstract Class and Methods
Class
Class having at least one abstract method is calledAbstract Class. They help to describe subclass to offer implementation details of the abstractclass and are used to provide some common functionality across a set of related classes.
Method
A method without body is called Abstract Method. Itmust be declared in an abstract class. Abstract Methods are generally used when two or moresubclasses are doing the same thing in different ways.
Why use Abstraction?
Well, as stated earlier, Abstraction reduces the complexity of OOPbut the main benefit of using an Abstraction in OOP is that it allows you to group several related classesas siblings. It also avoids code duplication and increases security of an application as only importantdetails are provided to the user.
Reference- TechTarget, Guru99
Get more information on tech topics only on The Info Docx.
👌
ReplyDelete