8. Interfaces
Interfaces in Go provide a way to specify the behavior of an object; “If something can do this, then it can be used here.” In this chapter, we look at how to use interfaces to abstract behavior. Later in this chapter, we explain how generics can be used to further refine interfaces. Concepts such as the Empty Interface
, satisfying multiple interfaces, value versus pointer receivers, and asserting for behavior also are covered in this chapter.
Concrete Types versus Interfaces
Interfaces allow you to specify behavior. They are about doing, not being. Interfaces also allow you to abstract code to make it more reusable, extensible, and testable.
To illustrate this, let’s consider the concept of a performance venue. A performance venue ...
Get Go Fundamentals: Gopher Guides now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.