Go's interfacing system is different from the interfacing systems in other languages. They are named collections of methods. Interfaces are important in composing readable Go code because they make the code scalable and flexible. Interfaces also give us the ability to have polymorphism (providing a single interface to items with different types) in Go. Another positive aspect of interfaces is that they are implicitly implemented—the compiler checks that a specific type implements a specific interface.
We can define an interface as follows:
type example interface {
foo() int
bar() float64
}
If we want to implement an interface, all we need to do is implement the methods that are referenced in the interface. The compiler validates your interface's methods so that you don't have to perform this action.
We can also define an empty interface...