What does data abstraction refer to? Please provide real life examples alongwith.
Abstraction has two parts:
For example, if I am designing a program to deal with inventory, I would like to be able to find out how many items of a certain type the system has in stock. From the perspective of the interface system, I don't care if I am getting this information from a database, a csv file, a remote repository via a SOAP interface or punch cards. I just care that I can can say widget.get_items_in_stock()
and know that it will return an integer.
If I later decide that I want to record that number in some other way, the person designing the interface doesn't need to know, care or worry about it as long as widget
still has the get_items_in_stock()
method. Like wise, the interface doesn't need to care if I subclass the widget class and add a get_square_root_of_items_in_stock()
method. I can pass an instance of the new class to it just as well.
So in this example, we've hidden the details of how the data is acquired and decided that anything with a get_items_in_stock()
method is an instance of the same class (or a subclass thereof) for certain purposes.