Think before you speak, read before you think.

golang interface

learn by doing

Interface is a protocol – a contract – an abstract type

It only describe the expected behavior

naming convention: abstract description

don’t use empty interface unless it’s necessary.

type foo interface{}

learn type switch:

func format(v interface{}) string {
switch v := v.(type) {
case int:
case string:
default:
}
}

When a type anonymously embeds a type, it can use the methods of the embedded type as its own

Interfaces: group types by behavior

Satisfy existing interfaces <- first thinking Interfaces are abstract bridges between types watch videos: https://www.udemy.com/course/learn-go-the-complete-bootcamp-course-golang


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *