liveBook · Manning

Internal API

As explained in Unit Testing Principles, Practices, and Patterns

The non-public operations and contracts through which internal implementation details are accessed within a software component.

An internal API, or private API, contains non-public operations and state used inside a component. Its members are implementation details rather than client-facing observable behavior. section 5.2 section 5.5

Classify internal API by asking what the client needs to achieve:

  • Expose operations or state that help clients achieve goals through the public API. section 5.2
  • Keep code that serves neither client goals nor observable results behind the internal API. section 5.5
  • Treat public exposure of implementation details as API leakage, because clients can bypass invariants and tests can couple to fragile internals. section 5.5

Hide normalization behind the observable operation

A User class initially exposes NormalizeName, while RenameUser calls it before assigning Name. The refactoring makes NormalizeName private and normalizes inside the Name setter, leaving user.Name = newName as the simpler public interaction. section 5.2

Figure 5.4. In a well-designed API, the observable behavior coincides with the public API, while all implementation details are hidden behind the private API.

Use the API-boundary diagram to distinguish a well-designed public API from its hidden implementation details. section 5.2

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains classification, leakage, encapsulation, and a User refactoring, but stops short of exhaustive API design guidance.
Examples
Uses User.NormalizeName and MessageRenderer.SubRenderers to show leaking operations and state, then hides them behind observable behavior.
What it assumes
Assumes basic software components and clients, while teaching public-versus-private API distinctions from first principles.
What you can do after
Evaluate API boundaries and refactor exposed implementation details behind operations or state that represent observable behavior.
How it connects
Connects private API with public API, observable behavior, implementation details, encapsulation, access modifiers, and test fragility.

Also explained in

Compare how 3 books explain internal API →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.