Member-only story

Advanced Go Coding — Interface Segregation Principle

Leveraging Small Interfaces for Cleaner, More Efficient Go Applications

Stefanie Lai
5 min readSep 23, 2024
from Unsplash

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.

Implementation Anti-ISP

--

--

Stefanie Lai
Stefanie Lai

No responses yet