Interface
An interface is a set of methods that describe the behavior of the data type. Interfaces define the behavior(s) of the type that must be satisfied to implement that interface. A behavior describes what that type can do. Almost everything exhibits certain behavior. For example, a cat can meow, walk, jump, and purr. All of those are behaviors of a cat. A car can start, stop, turn, and speed up. All of those are behaviors of a car. Similarly, behaviors for types are called methods.
Note
The definition that the https://packt.live/2qOtKrd provides is "Interfaces in Go provide a way to specify the behavior of an object."
There are several ways to describe an interface:
- A collection of method signatures is methods with only the name of the method, its arguments, types and a return type. This is an example of a collection of method signatures for the
Speaker{}
interface:type Speaker interface{ Speak(message string) string Greet() string }
- Blueprints...