7

Interfaces

Overview

This chapter aims to demonstrate the implementation of interfaces in Go. It is quite simple compared to other languages because it is done implicitly in Go, whereas other languages require interfaces to be implemented explicitly.

In the beginning, you will be able to define and declare an interface for an application and implement an interface in your applications. This chapter introduces you to using duck typing and polymorphism, accepting interfaces, and returning structs.

By the end of this chapter, you will have learned how to use type assertion to access your interface’s underlying concrete value and use the type switch statement.

Technical requirements

For this chapter, you'll require Go version 1.21 or higher. The ...

Get Go Programming - From Beginner to Professional - Second Edition 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.