liveBook · Manning

Abstraction level

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

An abstraction level is the degree of conceptual detail at which a method or other program element expresses its work.

Keep the work inside a method at a consistent level of abstraction: each operation should be expressed at a similar conceptual scale. Mixing a detailed loop with a high-level method call can make the method harder to read. section 2.5.3

public String evaluate() {
    String result = templateText;
    for (Entry<String, String> entry : variables.entrySet()) {
        String regex = "\\$\\{" + entry.getKey() + "\\}";
        result = result.replaceAll(regex, entry.getValue());
    }
    checkForMissingValues(result);
    return result;
}

This evaluator replaces variables in a loop, then checks for missing values with a method call—a mismatch in abstraction level. section 2.5.3

Refactoring the evaluator

Extracting variable replacement into its own method makes evaluate more balanced. Rerun the tests to check that the refactoring preserves behavior. section 2.5.3

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Explains inconsistent granularity through evaluator methods and demonstrates method extraction rather than defining a formal measure.
Examples
Uses a Java template evaluator that replaces variables, checks missing values, and is refactored into smaller methods.
What you can do after
Apply method extraction to separate work expressed at different abstraction levels, then rerun tests to check behavior.
How it connects
Connects abstraction level to method extraction, refactoring, and test-driven development.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.