Is hiding implementation detail Encapsulation or Abstraction?
Abstraction is all about providing an additional layer with interfaces and abstract classes.
This layer (interfaces and abstract classes) tells about what needs to be done, but NOT how. So hiding implementation is called as the abstraction.
The best example to understand the concept of abstraction is that all J2EE/JMS specifications provide abstractions (typically interfaces
) to the application vendors and then these interfaces will be implemented by the different vendors (like Tomcat/JBoss/Weblogic/ IBM/etc..) with the actual definitions/behavior (called implementations) for the specifications.
Abstraction talks only about WHAT needs to be done and
Implementation tells about HOW it should be done.
Abstraction provides the power of injecting the behavior at Runtime (which is Polymorphism). Now, taking Spring framework (or infact any DI framework like Guice, etc..) taking as example, the Spring DI container injects the provided bean (through xml or annotations) implementation object (implementation) at runtime to the given interface type (abstraction).
So does this mean object interface exposure is abstraction and the
data hiding inside object is encapsulation ?
Yes, almost, in Java abstraction can be achieved using interfaces
or sometimes using Abstract classes
(like J2EE HttpServlet
, etc..).
Now coming to the Encapsulation, it is all about providing/defining the right level of access for the classes/methods/fields (hiding/protecting the classes and class members). In Java, Encapsulation can be achieved using access modifiers (protected
/private
/public
/etc..).
You can look here for understanding more on abstraction in Java and here for overriding (implementation) and hiding methods.