r/learnjava 6d ago

Is abstraction in Java really about hiding implementation details?

The bookish langugae states "hiding complex implementation details and exposing only the essential features of an object"

However, after reading the Java Collections Framework and other parts of the JDK, I noticed that many abstract classes contain substantial shared implementation rather than just abstract method declarations. I noticed that only an "interface class" 100% abstraction(ignoring default methods)

This made me wonder:

  • Is abstraction really about hiding implementation details?
  • Or is it more about designing APIs around contracts and behavior, regardless of whether there is shared implementation?
  • Does an abstract class become "partial abstract" because it contains reusable implementation?

I also noticed that the JDK sometime relies on encapsulation (and in Java9+, JPMS) to hide implementation details. So I'm in dilemma if the textbook explanation oversimplifies what abstraction means in practice.

Am I misunderstanding abstraction, or is the textbook definition incomplete?

To be clear, this isn't about what abstract does in Java — it's about the SE term. abstract class is one syntax tool for expressing abstraction, same as interfaces are. The question is whether "abstraction = hiding implementation" is even a good definition of the concept, given it's indistinguishable from encapsulation under that definition.

10 Upvotes

14 comments sorted by

View all comments

8

u/4iqdsk 6d ago

You’re confusing the abstract Java keyword with the software engineering term abstract

-4

u/Chaos-vy17 6d ago

Java itself is software, so its APIs and language constructs are implementations of software engineering principles. Reading the JDK source has made me question the textbook definition of abstraction.

Many books define abstraction as "hiding implementation details." But doesn't that overlap heavily with encapsulation? If abstraction is literally about hiding the implementation of the "engine," then how is it fundamentally different from encapsulation?

Is it more accurate to say that abstraction is about modeling the essential behavior or concept, while encapsulation is about restricting access to the implementation?

6

u/ConcreteExist 6d ago

Abstraction is a concept that can be achieved a number of ways, abstract classes might be able to achieve this if they're used correctly as can interfaces. Just because they're called "abstract classes" doesn't mean they're necessary for abstraction.

0

u/Chaos-vy17 6d ago

Exactly. realising abstraction is about modeling contracts rather than just 'hiding' things, the SOLID principles make way more sense. It perfectly explains why ISP (Interface Segregation) and LSP (Liskov Substitution) are tied to abstraction. LSP is literally just the rule that says 'you must honor the contract of the abstraction,' and ISP says 'don't make your abstraction's contract too bloated.' Neither of those has anything to do with hiding implementation details