|  Home   |  Contact Us   |  Online Exam   |  Tech World   |  Jobs    |  Member Login
        Abstraction          

Abstraction is nothing but " Partial Implementation."
   It means to show only the necessary details to the client of the object.

Real Time Example:
     Do you know the inner details of the Monitor of your PC? What happen when you switch ON Monitor? Does this matter to you what is happening inside the Monitor? No Right, Important thing for you is weather Monitor is ON or NOT.

     When you change the gear of your vehicle are you really concern about the inner details of your vehicle engine? No but what matter to you is that Gear must get changed that’s it!! This is abstraction; show only the details which matter to the user.
Example:

     Let’s say you have a method "CalculateSalary" in your Employee class, which takes EmployeeId as parameter and returns the salary of the employee for the current month as an integer value. Now if someone wants to use that method. He does not need to care about how Employee object calculates the salary? An only thing he needs to be concern is name of the method, its input parameters and format of resulting member, Right?

     So abstraction says expose only the details which are concern with the user (client) of your object. So the client who is using your class need not to be aware of the inner details like how you class do the operations? He needs to know just few details. This certainly helps in reusability of the code.

     So now object is easy to understand and maintain also. As if there is any change in the process of some operation. You just need to change the inner details of a method, which have no impact on the client of class.
Code:

     /* File name : Employee.java */
     public abstract class Employee
     {
     private String name;
     private String address;
     private int number;
     public Employee(String name, String address, int number)
     {
     System.out.println("Constructing an Employee");
     this.name = name;
     this.address = address;
     this.number = number;
     }
     public double computePay()
     {
     System.out.println("Inside Employee computePay");
     return 0.0;
     }
     public void mailCheck()
     {
     System.out.println("Mailing a check to " + this.name + " " + this.address);
     }
     public String toString()
     {
     return name + " " + address + " " + number;
     }
     public String getName()
     {
     return name;
     }
     public String getAddress()
     {
     return address;
     }
     public void setAddress(String newAddress)
     {
     address = newAddress;
     }
     public int getNumber()
     {
     return number;
     }
     }

All Rights Reserved : skdotcom technologies