In general sense 'abstraction' mainly means presenting complex scenarios in a simpler fashion. And this could be achieved by creating some simpler interfaces to the complex scenarios. By creating such interfaces it is quiet evident that we trying to hide the complexity of the complex scenarios using the concept of abstraction.
In Object Oriented programming this concept of abstraction is implemented using methods that we create under a class. For example, consider a simple sort() of the Array class under System namespace. To sort a list of array elements we just need to call the sort() using the Array class.(Array.sort(arr_name)). By writing a single line of code we are able to perform complex functionality of sorting. But under the definition of sort() complex sorting algorithms are used which are hidden from the programmer. So the entire complex code for sort() is abstracted and is presented just as a simple method and this simple sort() becomes an interface for the user to perform sorting of array elements.
Eg: class Abs
{
public static void gcd(int a , int b)
{
if(a
{
int c=b%a;
if(c==0)
{
console.WriteLine(a); return;
}
int d=a%c;
if(d==0)
{
console.WriteLine(c); return;
}
...................;
}
}}
In the above class 'Abs', we defined a static method gcd() which performs gcd of 2 numbers. Writing this method is complex and time consuming for the programmer. To avoid this, we can allow programmer to directly call the gcd() under any class and use it-shown as follows:
class Test
{
static void Main()
{
Abs.gcd(3,4);
}
}
So we are abstacting the method gcd() from the programmer. That means we are allowing him to directly consume a method without showing him the definition for that method.