# Methods, Interfaces and Embedded Types in Go

DevFeed: [Methods, Interfaces and Embedded Types in Go](<https://devfeed.tech/articles/methods-interfaces-and-embedded-types-in-go-22100.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/05/methods-interfaces-and-embedded-types.html>)

Published: 2014-05-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [programming](<https://devfeed.tech/tags/programming.md>), [types](<https://devfeed.tech/tags/types.md>)

## AI overview

This Go tutorial explains methods, method sets, value and pointer receivers, interfaces, and embedded types. It examines how the compiler resolves interface implementations when both a struct and an embedded field implement the same interface.

## Source excerpt

Introduction My business partner Ed asked me what would happen if a struct and an embedded field both implemented the same interface. We asked ourselves two questions: Would the compiler throw an error because we now had two implementations of the interface? If the compiler accepted the type declaration, how does the compiler determine which implementation to use for interface calls? We hacked out some code to answer the questions and then I dug into the specification. What we found was really interesting and we believed worth sharing with others who are also learning the language. Once we learned the mechanics behind methods, interfaces, and embedded types, the answers seemed obvious. To get started, let's talk about what methods are in Go. Methods Go has both functions and methods. In Go, a method is a function that is declared with a receiver. A receiver is a value or a pointer of a named or struct type. All the methods for a given type belong to the type's method set. Let's declare a struct type and a method for that type: type User struct { Name string Email string } func (u User) Notify() error First we declare a struct type named User and then we declare a method named Notify with a receiver that accepts a value of type User. To call the Notify method we need a value or pointer of type User: // Value of type User can be used to call the method // with a value receiver. bill := User{"Bill", "bill@email.com"} bill.Notify() // Pointer of type User can also be used to call a method // with a value receiver. jill := &User{"Jill", "jill@email.com"} jill.Notify() In the case where we are using a pointer, Go adjusts and dereferences the pointer so the call can be made. Be aware that when the receiver is not a pointer, the method is operating against a copy of the receiver value. We can change the Notify method to use a pointer for the receiver: func (u *User) Notify() error Once again, we can call the Notify method like we did before: // Value of type User can be use