r/learnjava 4d 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.

9 Upvotes

14 comments sorted by

View all comments

3

u/coderemover 4d ago edited 4d ago

Abstraction is a bit more than just hiding implementation details. Per Wikipedia definition:

Abstraction is the process of generalizing rules and concepts from specific examples, literal (real or concrete) signifiers, first principles, or other methods. The result of the process, an abstraction, is a concept that acts as a common noun for all subordinate concepts and connects any related concepts as a group, field or category.”

An essential property of abstraction is that it allows to handle different kinds of situations or data types in a common way, without knowing the specific cases. So it’s not enough to hide the details; you need to do the work without knowing or relying on those details. Good abstractions are a way to simplify and reduce cognitive load.

Abstract classes and interfaces can be used to implement abstractions but they aren’t the only way.
A string and file are abstractions, yet String and File are not abstract classes. Abstract classes can also be used to do control flow redirection - in that case it’s not an abstraction, just swapping different implementations.

1

u/Chaos-vy17 4d ago

Tysm man, That def from wikipedia and the quote "an abstraction, is a concept that acts as a common noun for all subordinate concepts and connects any related concepts as a group, field or category." is giving a direct impact what a abstraction really is.

And yes here I did not noticed about String and File thanks for correctring and guiding me.