In my current job we use a lot of unexported interfaces. I’m struggling to get any capital gain from the use of these interfaces as it doesn’t act as a contract.
Is it a common practice to use these unexported interfaces?
Is there any other use of unexported (or private) interfaces?
Here is how we use them. We have large packages, each with a responsibility. In those packages, we add a function to adapt the calls to that package to each service that uses it. These functions can only be used by the service in question.
An example will be the save package. The package will have a save function that will never be called by any service. For each service, we will have a new function in the package that is associated with the service. Like SaveToGoogleDrive or SaveToAWS.
Back to the service, we will have an interface that only has the
SaveToGoogleDrive function, only that interface will be used. Obviously, this interface will be instantiated with the concrete type.
It’s the first type I’m working with in GoLang, and it’s very different from how I’ve used interfaces with over languages.
Edit: I have found that article that describe something that is looks like what we do.
We do the Do this instead part but with private interface. So we follow the advertised logic of “Define the interface at point of use.” I will keep searching.