Indirection inserts an intermediate abstraction layer between a caller and the concrete implementation or solution it needs. It can separate domain logic, application entry points, and infrastructure, but each added layer increases navigation and reasoning costs. section 8.5
Use indirection selectively:
- Keep a clear boundary between domain classes and controllers so unit and integration tests have distinct targets. section 8.5
- Prefer as few layers as possible; backend systems can often use a domain layer, application services layer, and infrastructure layer. section 8.8
- Replace callback-shaped circular dependencies with a value object returned from the callee. section 8.8
- Treat interfaces with one in-process implementation as a warning sign when they exist mainly to support mocks. section 8.8
Return the result instead of calling back
A checkout service that passes itself into a report generator creates a circular dependency. Refactor the generator to return a Report, allowing checkout to continue its work directly and removing unnecessary indirection.
