Implicit Interface Satisfaction in Go
Go types satisfy an interface automatically by having the right methods, with no explicit implements declaration. This structural typing decouples implementations from interface definitions, so you can define interfaces around how you use a type without…
In Go, a type satisfies an interface simply by possessing all the methods the interface declares, with no explicit declaration linking them. This structural, duck-typed approach means the type and the interface need not know about each other. The big consequence is decoupling: consumers can define small interfaces describing exactly the behavior they need, and any existing type that fits qualifies automatically.
Read the original → https://go.dev/tour/methods/10
- #go
- #interfaces
- #structural-typing
- #duck-typing
- #decoupling
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.