From the course: Advanced Go Programming: Data Structures, Code Architecture, and Testing

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Interfaces

Interfaces

- [Instructor] Now that we've established the characteristics of robust code and looked at how the principles of solid can be applied to Go code, it's time to turn our attention to their implementation using interfaces. In Go, interfaces are named collections of methods and they're the primary way to achieve polymorphism which is the ability to write code that works with different types at different times. Custom types or structs which define and implement the same methods as defined by the interface are set to satisfy that interface. Interfaces are easily defined using the interface keyword. Interfaces can contain zero or more method signatures. In this example, we define an Employee interface with a DoWork method. In order to satisfy an interface, structs need to define and implement the same methods as defined by the interface. There are no other keywords required. In this example, we define two structs: Engineer and…

Contents