On this page
Revision 1 November 5, 2026 abstraction-policy.md

Abstraction Policy

Type: Policy. How to recognize when shared code makes a project easier to work with.

A shared module is useful when it brings together a clear responsibility and simplifies its consumers. Repeated behavior, a complex independent operation, shared infrastructure work, or the need to verify a result independently can motivate extraction.

Reuse and decomposition

When code is used in one place, keep it there; in two places, consider whether a shared module is useful; in many places, extract the repeated part into a shared module.

This guideline helps assess reuse. Decomposition within the original module addresses a different task: an independent operation with a clear responsibility can become a function even when called only once.

Assessing an extraction

Matching lines do not necessarily mean matching behavior. Before extraction, it helps to understand which parts change for the same reason and which API would help their consumers. A clear module name and task make its value easier to assess.

Reusable code gets tests for the extracted behavior. These help preserve the shared contract as several consumers change.

Examples

Repeated configuration parsing can be collected in one module, and filesystem operations in an adapter, when several consumers need them.

A wrapper around a standard call is useful when it expresses an additional responsibility. If it merely repeats the call, the code is usually easier to read at the point of use. A utils.ts file makes sense when its task and consumers are clear.

Combining two similar fragments can hide an important behavioral difference. Clearer consumers and preservation of that difference help identify a suitable form for shared code. Preparing an abstraction for possible future use alone does not demonstrate that value.