From the course: Go for Developers: Practical Techniques for Effective Coding

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

What are interfaces?

What are interfaces?

- Interfaces allow us to specify behavior. They're about doing, not being. Interfaces allow us to abstract code to make it more reusable, extensible, and more testable. To illustrate this, let's consider the concept of a performance venue. A performance venue should allow a variety of performers to perform at the venue. The PerformAtVenue function here takes Musician as an argument, and calls the Perform() method on the Musician. The Musician type is a concrete type. Because the PerformAtVenue function takes Musician as an argument, which is a concrete type, we are restricted to who can perform at the venue. Here, we have a Poet type. The poet type also has a Perform() method just like the Musician's type. When we try to compile and run this application, oh... Let's create a new Poet and pass it to the PerformAtVenue function. When we try to compile and run this application, we get a compilation error telling us that a poet cannot be used as a musician. Interfaces allow us to solve…

Contents