Advanced Go Coding — Interface Segregation Principle
Leveraging Small Interfaces for Cleaner, More Efficient Go Applications
Interfaces, as the first-class “citizens” in the design of Go language, enable a flexible and powerful code structure. And an excellent interface design, such as, following some principles, can significantly improve code flexibility, maintainability, and testability of the code. In this article we will walk through the application of the Interface Segregation Principle(ISP) in Go and some implementation practices in the Go standard library to see how the principle works to facilitate cleaner and efficient code.
Interface Segregation Principle
interface segregation principle (ISP) states that no code should be forced to depend on methods it does not use — from wiki
ISP is one of the solid principles of object-oriented design with the core idea of “Clients shouldn’t be forced to depend on methods they do not use”. To be more specific, interfaces should be divided into smaller, more specific interfaces to make each interface more focused instead of creating a huge interface with too many methods, so that clients using these interfaces rely only on the functions they really need.