TLDR Web Dev · MISCELLANEOUS

DEFAULT METHODS IN GO

links.tldrnewsletter.com8 min read

Summary from the TLDR Web Dev newsletter

Go's structural typing system for interfaces creates problems when trying to add new methods without breaking existing code, as there is no way to provide default implementations. A workaround is to use Go's struct embedding feature combined with unexported interface methods to create "required embeds.” This forces interface implementers to embed a default struct that provides default method implementations.