The Liskov Substitution Principle (LSP) requires every implementation of an interface to work wherever that interface is expected without breaking application correctness. In Go, interfaces make this contract explicit while keeping consumers independent of concrete implementations. section 11.1.2
Apply LSP by designing around stable interfaces and interchangeable implementations:
- Define a Fetcher interface for retrieving and parsing feeds, allowing production readers, mocks, or future libraries to serve the same consumer. section 11.1.2
- Define Storage for persistence, while embedding the narrower ArticleReader interface for consumers that only need read access. section 11.1.2
- Depend on the smallest interface required: an HTTP handler accepting ArticleReader can use the full BoltStore or a test double without changing handler code. section 11.3.2
A read-only handler accepts multiple storage implementations
Define the handler around domain.ArticleReader, inject that dependency with New, and pass a concrete store or test stub. The handler relies on GetRecent and GetByID rather than BoltStore details, so production and testing implementations satisfy the same contract. section 11.3.2




