Technical Mid Level

How do interfaces in Go differ from interfaces in languages like Java or TypeScript? When do you define your own interfaces versus using standard library ones?

Quick Tip

Emphasise implicit satisfaction: "I define interfaces where they are consumed, not where they are implemented. This keeps packages decoupled and makes testing trivial — I just implement the two methods the function actually calls."

What good answers include

Go interfaces are satisfied implicitly — no "implements" keyword. This enables the consumer to define the interface they need rather than the producer declaring what it satisfies. Best practice: define small interfaces at the point of use, accept interfaces and return structs. Standard library interfaces like io.Reader, io.Writer, fmt.Stringer are composable building blocks. Strong candidates mention the "accept interfaces, return structs" principle and know when an interface with one or two methods is better than a large one.

What interviewers are looking for

Tests understanding of Go philosophy. Candidates from Java backgrounds often create large interfaces and declare them on the wrong side. Look for small, consumer-defined interfaces and understanding of why this matters for testing and decoupling.

← All Go questions