Fundamentals 22 min read

Why Abstract Thinking Is the Secret Weapon for Better Code Design

This article explains how abstract thinking underpins software engineering, covering definitions, the relationship between language and abstraction, levels of abstraction, layered design, the pitfalls of duplicate code and forced casts, and practical ways to strengthen one’s abstract reasoning skills.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Why Abstract Thinking Is the Secret Weapon for Better Code Design

What Is Abstraction

According to Baidu Baike, abstraction is the process of extracting common, essential features from many things while discarding non‑essential ones, forming concepts, judgments, and reasoning that reflect the essence and laws of phenomena. Wikipedia adds that abstraction filters information to keep only what is relevant to a specific purpose, simplifying the thing to its core.

Abstraction and Language Are One

Abstract thinking is essentially "word thinking" or conceptual thinking: we use words (concepts) as intermediaries to reflect reality. Naming a class, such as Cow, is an act of abstraction—the word represents all cows, even though we only see concrete instances.

Good naming reflects clear abstract thinking; poor naming often signals unclear abstraction and leads to maintenance headaches.

Levels of Abstraction

Using Picasso’s abstract cow as an example, an abstract class corresponds to the abstract cow, while concrete subclasses (WaterCow, MilkCow, etc.) correspond to specific instances. Three key characteristics of abstraction are:

Ignoring details – higher‑level abstractions discard more specifics.

Representing common properties – an abstract class captures shared traits of its subclasses.

Having hierarchy – higher abstraction has smaller intension and larger extension, thus stronger generalization.

Choosing the right level is crucial: too high loses expressive power, too low hampers extensibility.

Layered Abstraction in Software

Complex problems require layered abstraction. For example, the OSI model splits networking into seven layers, each handling a single concern. Programming languages also evolve through layers: binary → assembly → C → Java, each abstracting the lower level.

Duplicate Code Is a Lack of Abstraction

Repeated code indicates missing abstraction. A real‑world example shows a search‑condition assembly duplicated in many places. Extracting it into a SearchConditionAssembler class gives the concept a proper name and makes reuse explicit.

// extract default search conditions
List<String> defaultConditions = searchConditionCacheTunnel.getJsonQueryByLabelKey(labelKey);
for(String jsonQuery : defaultConditions){
  jsonQuery = jsonQuery.replaceAll(SearchConstants.SEARCH_DEFAULT_PUBLICSEA_ENABLE_TIME, String.valueOf(System.currentTimeMillis() / 1000));
  jsonQueryList.add(jsonQuery);
}
// assemble main search box conditions
if(StringUtils.isNotEmpty(cmd.getContent())){
  List<String> jsonValues = searchConditionCacheTunnel.getJsonQueryByLabelKey(SearchConstants.ICBU_SALES_MAIN_SEARCH);
  for (String value : jsonValues) {
    String content = StringUtil.transferQuotation(cmd.getContent());
    value = StringUtil.replaceAll(value, SearchConstants.SEARCH_DEFAULT_MAIN, content);
    jsonQueryList.add(value);
  }
}

Forced Type Casting Signals Bad Abstraction Levels

When code relies on instanceof checks and casts, it often violates the Liskov Substitution Principle. For example, a FruitPicker that checks Apple and Watermelon separately can be refactored by introducing an abstract isTasty() method on Fruit:

public class FruitPicker {
    public List<Fruit> pickGood(List<Fruit> fruits){
        return fruits.stream().filter(e -> e.isTasty()).collect(Collectors.toList());
    }
}

This eliminates casts and restores LSP compliance.

How to Improve Abstract Thinking

Practical ways include:

Read more – books force you to visualize and abstract concepts.

Summarize and reflect – writing notes in your own words deepens understanding.

Naming practice – each variable, method, or class name is a mini‑abstraction exercise.

Domain modeling – analyzing and structuring problem domains sharpens abstraction skills.

Conclusion

Abstract thinking is the most important cognitive skill for programmers.

Language and abstraction are inseparable; good naming reflects clear abstraction.

Abstraction has levels: higher levels give better generalization but weaker expressiveness.

Balancing abstraction depth is a hallmark of strong design.

Duplicate code and forced casts are signals of missing or misplaced abstraction.

Deliberate practice—reading, summarizing, naming, and modeling—can significantly boost abstract thinking.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Modelingsoftware designcoding practicesObject-Orientedabstraction
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.