Sobes.tech
Senior

What interfaces would you implement?

sobes.tech AI

Answer from AI

In Go, interfaces are usually implemented to define behaviors that different types can have. At the senior level, interfaces are often created to abstract dependencies, for example:

  • Interface for working with a database (CRUD operations)
  • Interface for logging
  • Interface for caching

This allows for easy swapping of implementations without changing business logic.

Example of a repository interface:

// UserRepository describes methods for working with users
type UserRepository interface {
    GetByID(id int) (*User, error)
    Save(user *User) error
}

Implementation can vary: with a database, with mocks for testing, etc.

What interfaces would you implement? — Golang - sobes.tech