Data abstraction

Abstraction is the process is used to hide certain details and only show the essential features of the object.
It is class level design that hiding the complexity of the implementation and offered by an API / design / system, in a sense simplifying the 'interface' to access the underlying implementation.


Example:


  1. public class Employee
  2. {
  3.    private String name;
  4.    private String address;
  5.    private int sal;
  6.    public Employee(String name, String address, int sal)
  7.    {
  8.       this.name = name;
  9.       this.address = address;
  10.       this.sal = sal;
  11.    }

  12.    public void getDetails()
  13.    {
  14.       System.out.println("Emaplyee details " + this.name + " " + this.address + " " + this.sal);
  15.    }
  16.    public String toString()
  17.    {
  18.       return name + " " + address + " " + sal;
  19.    }
  20.    public String getName()
  21.    {
  22.       return name;
  23.    }
  24.    public String getAddress()
  25.    {
  26.       return address;
  27.    }
  28.    public void setAddress(String newAddress)
  29.    {
  30.       address = newAddress;
  31.    }
  32.    public int getSal()
  33.    {
  34.      return sal;
  35.    }
  36. }

  37. public class AbstractionDemo
  38. {
  39.    public static void main(String [] args)
  40.    {

  41.       Employee emp = new Employee("XYX", "Hyderabad,India", 89000);

  42.       System.out.println("Getting Employee Details");
  43.       emp.getDetails();
  44.     }
  45. }

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation