liveBook · Manning

Abstraction

As explained in Simple Object-Oriented Design: Create clean, maintainable applications

An abstraction is a simplified model that exposes relevant behavior or structure while hiding unnecessary implementation details.

An abstraction describes a concept, function, or process through its essential behavior while hiding the mechanisms behind it. It separates what clients need to know from how the work is performed, creating a precise contract rather than a vague one. section 5.0 section 5.1.3

Its purpose is to control complexity as a system evolves. When every new variation is added to the same class through more conditionals or copied blocks, that class becomes harder to change and test. An abstraction provides an extension point: new behavior can be introduced as another implementation instead of modifying established code. section 1.2.4 section 5.1

Discount rules

Start with direct code for one or two discount rules. As rules accumulate—such as seasonal discounts, quantity offers, and e-book promotions—repeated changes and long runs of if statements signal variability worth modeling. Define a small discount abstraction, then add each rule as a concrete implementation so rules can be plugged in, removed, or combined without changing the calling code. section 5.0 section 5.3.3 section 5.1.3

A useful abstraction has these properties:

  • States a clear, lean contract: clients provide only necessary inputs and receive only what they need. section 5.1.3
  • Hides implementation choices so clients can understand the flow without knowing concrete implementations. section 5.1.3
  • Stays small, leaving nonessential work to concrete implementations. section 5.3
  • Remains stable enough that clients can depend on it without frequent breaking changes. section 5.1.3 section 5.1.4

Do not abstract merely for elegance. Abstractions add indirection and make polymorphic flows harder to follow. Favor simple code when flexibility is uncertain, but introduce an abstraction when variation, composition, likely change, or hidden decisions justify its cost. Waiting for repeated pressure is sensible; acting early is also reasonable when future flexibility is clear. section 5.1.1 section 5.3.2 section 5.3.4

Infrastructure is a common boundary for abstraction. Isolate database, remote-service, caching, or file-storage details to limit the effect of change and support isolated tests. Do not pretend those details do not exist, however: over-hiding a relational database or remote call can obscure constraints developers need to design correctly. section 6.0 section 6.1.2

Figure 5.4 Three rules to help you decide whether to create an abstraction or extension point

Use the decision guide to weigh flexibility against the extra complexity of an abstraction or extension point. section 5.3.1

How Simple Object-Oriented Design: Create clean, maintainable applications covers it

How deep it goes
Defines abstractions, contracts, extension points, decision triggers, and maintenance tradeoffs, while deferring implementation and design-pattern instruction.
Examples
Uses bookstore discount rules, growing conditional classes, databases, remote services, caching, and file storage.
What it assumes
Assumes object-oriented fundamentals and uses interfaces and concrete implementations without teaching them from zero.
What you can do after
Apply it by identifying variability or leaking details, then introducing a small stable contract and concrete implementations.
How it connects
Connects abstractions with extension points, modularity, coupling, dependency management, encapsulation, and infrastructure.

Also explained in

Compare how 15 books explain abstraction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Simple Object-Oriented Design: Create clean, maintainable applications. The section links point to the parts of the book it draws on.