Programming Languages
Go
Subjective
Oct 04, 2025
Explain interfaces in Go and how they work.
Detailed Explanation
Interfaces in Go:
• Define a set of method signatures
• Implemented implicitly (duck typing)
• Enable polymorphism
• Can be empty (interface{})
• Support type assertions
• Enable dependency injection
Example:
type Writer interface {
Write([]byte) (int, error)
}
type File struct{}
func (f File) Write(data []byte) (int, error) {
// Implementation
return len(data), nil
}
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts