Abstraction is the process to hide the internal details(business login) and showing only essential functionality to the end users.
Abstraction achieved by two ways
- Abstract Class
- Interface
Example:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABSTRACTION
{
class Employee
{
public int EmpId;
public string EmpName;
public double GrossPay; // 25000 // house rent -- 5000, convence allowance - 4000
double TaxDeduction = 0.1; // 10%
double netSalary;
public Employee(int Eid, string Ename, double Egrosspay)
{
this.EmpId = Eid;
this.EmpName = Ename;
this.GrossPay = Egrosspay;
}
void CalculateSalary()
{
if(GrossPay >= 30000)
{
netSalary = GrossPay - (TaxDeduction * GrossPay);
Console.WriteLine("Your Salary is: {0}", netSalary);
}
else
{
Console.WriteLine("Your Salary is: {0}", GrossPay);
}
}
public void ShowEmployeeDetails()
{
Console.WriteLine("Employee Id is: {0}",this.EmpId);
Console.WriteLine("Employee Name is: {0}", this.EmpName);
this.CalculateSalary();
}
}
class Program
{
static void Main(string[] args)
{
Employee Ali = new Employee(333,"Ali Khan",25000);
Ali.ShowEmployeeDetails();
Console.ReadLine();
}
}
}
In above program we make an object of Emoloyee class and call the ShowEmployeeDetails() and hide CalculateSalary() so this program we hide the internal login (CalculateSalary)