What is abstraction?
The basic abstraction in Java is a class. A class can be used to hide certain implementation details and only show the essential features of the object. Abstraction focuses on the observable behavior of an object.A class models an abstraction by defining the properties and behaviors for the objects representing the abstraction. An object exhibits the properties and behaviors defined by its class.
class Employee {
private int employeeId;
private String employeeName;
public int getEmployeeId(){
return this.employeeId;
}
}
Here Employee is an abstraction and it models an abstraction by defining employee details like employeeId and employeeName. Methods inside Employee like getEmployeeId() define the behavior of abstraction.
To the user(most probably another class) who is using Employee object to get an employee Id, the implementation details are hidden.
eg: Imagine a media player. It abstracts the concepts of playing, pausing, fast-forwarding, etc. As a user, you can use this to operate the device.
"One point of confusion regarding abstraction is its use as both process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item."
I found lot of articles in internet confusing the readers with the concept of abstract class with abstraction and with my experience of Java programming - these two are different concepts.
abstract classes and interfaces are used to implement inheritance and class is a basic abstraction in Java.
No comments:
Post a Comment