Go doesn't have covariance/contravariance or auto casting between identical interfaces.
What it means in context of using interfaces in the package of invocation is that if you have a local interface Handler that uses another local interface, Message it cannot be implemented without importing the Message, and different callers cannot have different interfaces.
type Message interface {
GetText() string
}
type Handler interface {
Handle(msg Message)
}
More to that, if the local interface if not exported (i.e. message, lowercase) it cannot be implemented at all outside of the package.
The only solution I see is to have a common "interface" package and use it in both places, which this article is against.
So the question is – what would you propose in that case?
Go doesn't have covariance/contravariance or auto casting between identical interfaces.
What it means in context of using interfaces in the package of invocation is that if you have a local interface
Handlerthat uses another local interface,Messageit cannot be implemented without importing theMessage, and different callers cannot have different interfaces.More to that, if the local interface if not exported (i.e.
message, lowercase) it cannot be implemented at all outside of the package.The only solution I see is to have a common "interface" package and use it in both places, which this article is against.
So the question is – what would you propose in that case?