Abu Bakar
Feb 3, 2025

Don’t create interfaces for types that only have one implementation. Instead, export the concrete type directly. It lets users define their own interfaces if needed. Suppose, you have a FileLogger struct with a Log() method, don’t export a Logger interface for it. Just export FileLogger. Users who need an interface can define one themselves, like type CustomLogger interface { Log() }, and use FileLogger with it. It will keep your code simple and avoid forcing unnecessary abstractions on others.

--

--

Abu Bakar
Abu Bakar

Written by Abu Bakar

Polyglot Software Engineer | Building end-to-end, turnkey solutions for web | Designer who loves minimalism

No responses yet