Module 04 of 12

Methods & Interfaces

Lessons

About This Module

Go does not have classes. Instead, you attach behavior to your own types with methods and describe shared behavior with interfaces. This small, flexible model is behind most idiomatic Go code, from the standard library to large production systems.

This module starts with pointers, since they decide whether a function or method works on a copy or on the original value. It then covers struct methods, how to choose between value and pointer receivers, and finally interfaces, which let different types be used through the same set of behaviors.

Watch the lessons in order and experiment with your own types, then continue on to Error Handling.

Lessons

4 videos
01

Golang Tutorial #19: Pointers & Dereference Operator (& and *)

Pointers in Go: the difference between reference and value, when you should use a pointer, and how the address and dereference operators work.

02

Golang Tutorial #21: Struct Methods

Struct methods: attaching functions to your own types so that data and behavior live together.

03

Value vs. Pointer Method Receivers in Go

A detailed look at value and pointer receiver methods with examples, so you can decide which one a method should use.

04

Golang Tutorial #22: Interfaces

Interfaces in Go: describing behavior so that different types can be used interchangeably.