I am little confused about abstraction in java.
I have checked many pages stating that abstraction is data hiding(Hiding the implementation).
What I understa
It is not hiding the information from you, but from the client of your abstraction. Take a look at this example.
public class Demo {
Client client = new Client(new Implementation());
}
public interface Abtraction {
void doWork();
}
public class Implementation implements Abtraction{
@Override
public void doWork() {
//doingTheWork
}
}
public class Client{
private Abtraction theAbstraction;
public Client(Abstraction theAbstraction){
this.theAbstraction = theAbstraction;
}
}
The class Client
is unaware of the implementation of Abstraction
, this means that the Demo
class can provide different implementations of Abstraction
without messing up the Client
.