what is data abstraction and data encapsulation
Answers
Answer:
Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation.
Encapsulation is an Object Oriented Programming concept that binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse.
Explanation:
Let's take an example 1: When you eat food or drink water you only care about filling your stomach and Information about digestion of food, breaking of complex carbohydrates and etc are all kept hidden by your body.
Example 2: A man driving a car. The man only knows that pressing the accelerators will increase the speed of car or applying brakes will stop the car but he does not know about how on pressing accelerator the speed is actually increasing, he does not know about the inner mechanism of the car or the implementation of accelerator, brakes etc in the car. This is what abstraction is
Example 3: When you use your smart phone you just click on the button. Actually when you click a What function it should perform is written in form of Programming language. You can only click button, but you cannot change the fucntion of the button. Can you change the funtionality of back button permanently ? No, you can't only programmers are allowed to do that.
"One way to achieve abstra ction is using setter and getter functions "
Let take an example for Encapsulation
See the above capsule. You eat it when you are not felling well. Inside that capsule there are very small medicine packed into one unit and helps you to recover and function your body correctly.
Consider a real life example of encapsulation, in a company there are different sections like the accounts section, finance section, sales section etc. The finance section handles all the financial transactions and keep records of all the data related to finance. Similarly the sales section handles all the sales related activities and keep records of all the sales. Now there may arise a situation when for some reason an official from finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of sales section and the employees that can manipulate them are wrapped under a single name “sales section”.
Encapsulation also lead to data abstraction or hiding. As using encapsulation also hides the data. In the above example the data of any of the section like sales, finance or accounts is hidden from any other section.
Data Abstraction : it is used to hide certain details and show only the essential features.
Data encapsulation:the combination of data and function in a combined single unit.