Compose Go interfaces by embedding existing interfaces to inherit their methods and create new, combined contracts.
Compose interfaces in Go by embedding one interface inside another to inherit its methods. The resulting interface requires the embedded methods plus any new ones you define.
type Reader interface {
Read(p []byte) (n int, err error)
}
type Writer interface {
Write(p []byte) (n int, err error)
}
type ReadWriter interface {
Reader
Writer
}
Interface embedding lets you build complex contracts by combining smaller, existing ones. Think of it like stacking requirements: if you need something that can both read and write, you just stack the 'Reader' and 'Writer' rules together. The final interface demands that any type implementing it must satisfy all the rules from the stacked interfaces.