Stable Abstractions Principle

No Change
adopt
First Added:June 25, 2026 Updated: July 2, 2026

Stable Abstractions Principle is a technique we adopt in the garden.

Summary

When to use: Evaluate on a project when the capability clearly fits the requirement.

When to skip: When a simpler alternative already covers the need.

Details

Abstraction Metric

Abstraction (A) for a package:

A = N_i / (N_i + N_c)

Where N_i is the count of interfaces (and abstract types) and N_c is the count of concrete classes. A ranges from 0 (fully concrete) to 1 (fully abstract). SAP expects stable packages to score higher on A.

Stability vs Abstraction Quadrants

ProfileRisk
Stable + concreteZone of pain: hard to change, many dependents hurt
Stable + abstractTarget: extend via new implementations
Unstable + abstractZone of uselessness: abstractions nobody uses
Unstable + concreteNormal for feature and adapter code at the leaves

Component Coupling Context

SAP is one of three classic component coupling principles (Robert C. Martin). Siblings are Acyclic Dependencies Principle (ADP) and Stable Dependencies Principle (SDP).

PrincipleGist
ADPNo cycles (Acyclic Dependencies Principle)
SDPDepend toward stability (Stable Dependencies Principle)
SAPStable components stay abstract

Practical Signs

SignalLikely fix
Shared library is concrete classes with wide import fan-inExtract interfaces; move concretions to unstable packages
Subclassing stable types breaks invariants (Liskov Substitution Principle)Prefer composition and ports over deep inheritance
Interface-only jar with no implementationsMerge with a consumer or add reference impl (avoid uselessness zone)
Stable API changes require editing the same file weeklySplit volatile concretions per Common Closure Principle

Common Failure Modes

  • Abstract stable packages with no real extension points (speculative SAP)
  • Concrete stable god modules that every team imports
  • Confusing SAP with “never put code in stable packages” (stable still needs some abstraction)
  • Deep inheritance hierarchies in stable layers instead of small interfaces

Related Garden Items