2

If we can use the default and static methods in the Interface and implement it in other classes, then how can we say that the interface achieve 100% abstraction?

subash poudel
  • 37
  • 1
  • 7

1 Answers1

2

Can we say that the interface achieve 100% abstraction?

I think we can still say that. Or at least we can say that static and default in an interface don't make it any harder to achieve 100% abstraction1.

A static method in an interface is no different to a static method in a class. In both cases, the method API is the abstraction boundary for the code in the method's body.

We can make the same argument for a default method. The method body may do things that are common to the implementation of all instances of all descendents of the interface, but the details are still hidden from the caller. That is the abstraction boundary.

What default and static methods are doing is to allow the abstraction boundary to be implemented further up the inheritance graph. If you are using them correctly, this is a good thing because it is removing redundant or duplicative code.


1 - It is up to the programmer to design and implement an API to not be a leaky abstraction. Simply using interfaces doesn't address this.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216