© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
A. FreemanPro Gohttps://doi.org/10.1007/978-1-4842-7355-5_11

11. Using Methods and Interfaces

Adam Freeman1  
(1)
London, UK
 
In this chapter, I describe the Go support for methods, which can be used to provide features for structs and to create abstraction through interfaces. Table 11-1 puts these features in context.
Table 11-1

Putting Methods and Interfaces in Context

Question

Answer

What are they?

Methods are functions that are invoked on a struct and have access to all of the fields defined by the value’s type. Interfaces define sets of methods, which can be implemented by struct types.

Why are they useful?

These features allow types to be mixed and used through ...

Get Pro Go: The Complete Guide to Programming Reliable and Efficient Software Using Golang 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.