The idea of representing significant details and hiding details of functionality is called data abstraction. The interface and the implementation are isolated by this programming technique. Data abstraction is one of the object oriented programming features as well. Abstraction is trying to minimize information so that the developer can concentrate on a few ideas at a time. Abstraction is the foundation for software development.
Consider a real-life example of making a phone call. The only thing the person knows is that typing the numbers and hitting the dial button will make a phone call, they don’t know about the inner system of the phone or the dial button on the phone. That’s what we call abstraction.
Another real-life example of abstraction is as users of television sets, we can switch it on or off, change the channel and set the volume without knowing the details about how its functionality has been implemented.
Data Abstraction in modules: In Ruby, Modules are defined as a set of methods, classes, and constants together.For example, consider the sqrt() method present in Math module. Whenever we need to calculate the square root of a non negative number, We simply call the sqrt() method present in the Math module and send the number as a parameter without understanding the actual algorithm that actually calculates the square root of the numbers.
Data Abstraction in Classes: we can use classes to perform data abstraction in ruby. The class allows us to group information and methods using access specifiers (private, protected, public). The Class will determine which information should be visible and which is not.
Data Abstraction using Access Control: There are three levels of access control in Ruby (private, protected, public). These are the most important implementation of data abstraction in ruby. For Example-
- Members who have been declared public in a class can be accessed from anywhere in the program.
- Members declared to be private in a class can only be accessed from within the class. They are
not allowed to access any part of the code outside the class.
In Public! In Private!
In the above program, we are not allowed to access the privateMethod() of Geeks class directly, however, we can call the publicMethod() in the class in order to access the privateMethod().
Advantages of Data Abstraction:
- Helps increase the security of a system because only crucial details are made available to the user.
- It increases re-usability and prevents redundancy of code.
- Could alter the internal class implementation independently without affecting the user.
- Ruby | Data Types
- Understanding Encapsulation, Inheritance, Polymorphism, Abstraction in OOPs
- GRE Data Analysis | Distribution of Data, Random Variables, and Probability Distributions
- GRE Data Analysis | Numerical Methods for Describing Data
- Difference between Data Scientist and Data Engineer
- Difference Between Data Science and Data Engineering
- Difference Between Data Science and Data Visualization
- GRE Data Analysis | Data Interpretation Examples
- Difference Between Data Visualization and Data Analytics
- Difference between Data Lake and Data Warehouse
- Difference Between Data Mining and Data Visualization
- Difference Between Data Mining and Data Analysis
- Difference Between Data Science and Data Analytics
- Difference Between Data Science and Data Mining
- Difference between data type and data structure
- GRE Data Analysis | Methods for Presenting Data
- Difference Between Big Data and Data Mining
- Difference Between Small Data and Big Data
- Difference Between Big Data and Data Warehouse
- Difference Between Big Data and Data Science
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.