Abstraction

ABSTRACTION:


Abstraction is the act of representing essential features without including the background details or explanations.


See the example below:


#include
using namespace std;

int main() {
cout << "Welcome";
return 0;
}


Here, cout will print the message Welcome, but how we dont know, its an example of abstraction.


If we go through general life example, take an example of TV remote. We know channel will get changed on pressing channel change button, but how its work that’s not shown.


In object-oriented programming, There are three central principles:
  1. Abstraction 
  2. Encapsulation and 
  3. Inheritance.


There are two types of abstraction:
  1. Functional abstraction
  2. Data abstraction


1. Functional abstraction:
Functional abstraction means, a function that can be used without taking into account how the function is implemented.
It requires a specific interface to invoke the function.


Example of functional abstraction:
#include
using namespace std;


class functionalAbstraction
{
private:
void show()
{
cout<<"I am in in a private function";
}
public:
void set()
{
show();
}
};
int main()
{
functionalAbstraction obj;
obj.set();
return 0;
}


OUTPUT:
I am in private function.


In above program function show() is declared as private. Function set() is called in main(). main() shows output is from set(), but actually its from show().


2. Data abstraction:
Data abstraction means, a data that can be used without taking into account how the data are stored.
It required the specific set of operations to examine and manipulate the data.
Example of Data abstraction:


#include
using namespace std;

class dataAbstraction
{
private:
int x, y;
public:
void set(int a, int b)
{
x = a;
y = b;
cout<<"x = " <
cout<<"y = " << y << endl;
}
};
int main()
{
dataAbstraction obj;
obj.set(4, 6);
return 0;
}


OUTPUT:
x = 4
y = 6

In above program variables x and y are declared as private. Than x and y are examined through the function set(). Its not known where the data is stored because x and y are declared as private.

Related topics

Professor Jayesh video tutorial

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.