Model data and behaviour with Go's type system by defining structs, attaching methods, and designing with interfaces. You will learn embedding and composition, when to use pointer versus value receivers, how implicit interface satisfaction works, and how to encapsulate state cleanly — so you can honestly design idiomatic Go types on the job.
Watch the free preview
Defining structs and creating values — free to watch, no account needed.
What you'll learn
- Model data and behaviour with Go's type system using structs, methods and interfaces
- Compose types with struct embedding and promoted fields instead of inheritance
- Choose correctly between pointer and value receivers for methods
- Design and satisfy interfaces implicitly, including the empty interface and type switches
- Encapsulate state with packages, exported identifiers and constructor functions
Syllabus
Modelling Data with Structs
Defining structs and creating valuesFree preview
Composition and embedding
Adding Behaviour with Methods
Methods and receivers
Pointer vs value receivers
Interfaces and Implicit Satisfaction
Defining and satisfying interfaces
Designing with small interfaces
The Empty Interface, Type Assertions & Encapsulation
The empty interface, assertions and type switches
Encapsulation with packages and exported names
Lab — 10 Exercises & Solutions
Exercises 1–5
Exercises 6–10