What is Abstraction in OOPs is an important question in programming. When you start learning a programming language nowadays. You realize that you will have to learn Object-Oriented Programming concepts. As soon as you start understanding Object Oriented programming concepts, you come to know that we have 6 concepts in OOPs which are mentioned below.
Abstraction is one of those 6 basic concepts of programming. Usually, Abstraction is literally omnipresent. Let me give you an example.
When you began to learn how to drive a car, did you feel you will have to know the mechanism of a car engine? I know your answer will be No. I mean it’s a good idea if you know it but you can learn to drive without mastering the working of an engine.
You just need to know the basics or your car.
- How to start your car?
- How to stop it?
- How to take a turn.
- What type of fuel your car consumes?
- How many gears are there in your car or it’s an automatic car?
- The traffic rules and presence of mind obviously.
With the above information you can be a good driver. But do you know there are a lot of things those are hidden from your view. Those complex things are
- The design of an engine.
- What gives that engine so much power. How does an engine generate so much thrust?
- What happens inside an engine when you start or stop the car.
- What happens when you use the breaks and how does a car stops.
Why do these things are hidden and why you don’t need to know it? The simple answer is because they are complicated. This is the definition of Abstraction.
What is Abstraction in OOPs
Hiding the body of complex classes in programming and revealing only what is necessary. This is termed as Abstraction in the programming world.
When we say showing only what is necessary, it means you only need to know what type of and how many parameters that class will take to give you your desired output.
For example, We have been using Console.WriteLine() to write something on the console screen. If you are a good student of programming, you would know there is a Console class and inside that, there is a method called WriteLine. You are making use of the WriteLine method to print something on the console screen but you don’t need to know the code of the WriteLine method. This is called Abstraction.
Benefit of Abstraction
Abstraction is something that allows you to use everything in modules. Once you have created something complicated after a lot of brainstorming. You can make that available to the next generation programmer as a module. The next generation programmer will use that module and take the benefit of your hard work without even knowing how you coded that module that he is using as a tool in the form of a module. It will save him a lot of time and effort.
The time he will save using your class as a module he can use that time to create something more complicated using your module and make that available to the next generation.
Drawback of Abstraction
I watched the interview of a computer scientist who was putting his two cents on the drawbacks of Abstraction, I agreed with what he mentioned.
He said, Abstraction in programming can be useful at times but the Abstraction in the real world is a bit harmful. He says, devices that we are using nowadays are very complicated, we need some minds who understand the way these devices work. For example, an iPhone is an incredible piece of engineering. The phone has only one button that does everything, the kids nowadays know how to use an iPhone but these kids are likely future scientists and engineers.
Not only the iPhone but the majority of electronic devices nowadays are the use and destroy. The devices are designed in such a way that they are just a combination of modules working together and can be fixed easily without even understand how these modules are working together. If the kids will not understand their complexity, their critical thinking will not develop hence we will be in trouble at some point in the future.
This was it. I hope you have understood what is Abstraction in OOPs and Abstraction in general. In case of any confusion, feel free to comment. I will be glad to read your comments.
Stay Safe Stay Healthy!