Skip to content

[local-interfaces] What do you do with more complex interfaces? #1

Description

@awryme

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions