When to use interfaces

At work, I love to use itnerfaces:

  • when there is an entity that has multiple implementations
  • to separate layers of our application (top layers have interface fields to bottom layers)
  • to separate domain objects (each domain object has its own interface and usually mocks as well)

I am getting a lot of flack from a colleague that says this interface overuse is making it hard for him to follow my code (to ctrl+click on code, in his IDE, and get to the domain object who causes a given functionality), because when he clicks on an interface his IDE takes him to the interface definition and not the interface implementation.

Am I in the wrong here ? What is the idiomatic way to do it in Go ? His rule is to have interfaces only for something with multiple implementations, or only for mocking external systems (for example, does not allow mocking another domain object in the same repo)

nterfaces are used to model behavior and define a contract that an object has to fulfill. They are useful for:

  1. specify the behavior of a particular data type, but don’t worry about who implements your behavior.
  2. take advantage of multiple inheritances.
  3. expects unrelated classes to implement its interface.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.