Grzegorz Wilczyński
banner
lunarem.bsky.social
Grzegorz Wilczyński
@lunarem.bsky.social
„I wish there was a way to know you're in the good old days before you've actually left them.” - Andy Bernard

#rust #golang #softwarearchitecture
As an appendix, I recommend this article 100go.co/5-interface-..., and the entire book www.manning.com/books/100-go... in general
Interface pollution (#5) - 100 Go Mistakes and How to Avoid Them
None
100go.co
January 16, 2025 at 3:08 PM
✨ Testability and Mocking. When the factory function returns the struct, consumers can create their own interfaces based on their specific needs. This makes it easier to mock the behavior for testing since the interface can be narrower and focused on the specific methods the test cares about.
January 16, 2025 at 3:08 PM
✨ Interface Segregation. Returning the concrete struct allows you to add methods to the struct in the future without breaking backward compatibility. If you return an interface and later need to add a method, all implementations of that interface need to be updated, which can be disruptive.
January 16, 2025 at 3:07 PM
This decouples the producer from the consumer and avoids forcing a specific abstraction on the user of the handler.
January 16, 2025 at 3:07 PM
✨ Interfaces Should Be Defined by Consumers. Interfaces are generally more useful when defined by the consuming code rather than the producing code. Returning a concrete struct instead allows the consumer to define and use their own interfaces as needed.
January 16, 2025 at 3:07 PM
It’s really hard to believe that it’s true 😅
December 14, 2024 at 9:08 PM