Interfaces
An interface is a Go mechanism for defining behavior that is implemented using a set of methods. Interfaces have a core role in Go and can simplify the code of your programs when they have to deal with multiple data types that perform the same task—recall that fmt.Println()
works for almost all data types.
But remember, interfaces should not be unnecessarily complex. If you decide to create your own interfaces, then you should begin with a common behavior that you want to be used by multiple data types. Additionally, you should not design your programs by defining interfaces. You should start designing your program and wait for common behaviors to reveal themselves and then convert those common behaviors into interfaces. Last, if the use of interfaces does not make your code simpler, consider removing some or all of your interfaces.
Interfaces define none, a single, or multiple type methods that need to be implemented. As you already know, once you implement...