Technical Senior Level

How do you design Go structs and packages to maintain clean architecture? What does "accept interfaces, return structs" mean in practice?

Quick Tip

Give a practical example: "My service constructor accepts an interface for the database layer but returns *UserService. Tests pass a mock implementing just the two methods used. Callers get the full concrete type."

What good answers include

Functions should accept interface parameters to remain flexible and testable, but return concrete struct types so callers have full access to the implementation. Package design: keep packages small and focused, avoid package-level state, use internal/ for implementation details, and name packages by what they provide not what they contain. Strong candidates discuss the standard library as a model for package design and mention avoiding circular dependencies.

What interviewers are looking for

Tests architectural maturity in Go. Candidates from OOP backgrounds often create unnecessary abstractions. Go favours simplicity — look for flat package structures, minimal interfaces, and concrete return types.

← All Go questions