Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Make Sender so that it can't be implemented externally.#116

Merged
keep94 merged 1 commit intowavefrontHQ:masterfrom
keep94:sender-pinterface
Nov 8, 2022
Merged

Make Sender so that it can't be implemented externally.#116
keep94 merged 1 commit intowavefrontHQ:masterfrom
keep94:sender-pinterface

Conversation

@keep94
Copy link
Copy Markdown
Contributor

@keep94 keep94 commented Oct 24, 2022

This is another way to ensure that we can add methods to Sender as non-breaking changes. This works but it is weird because we declare a 9 method interface in GO, a language where interfaces with just 1 or 2 methods are common. Also, note that there is not a way to write examples for interface methods in GO. I think this is by design.

The up side to this solution is that it won't break most existing clients.

@oppegard
Copy link
Copy Markdown
Contributor

oppegard commented Nov 7, 2022

@keep94 this seems ok, but also forces the issue. I'm not sure if there's a correct or idiomatic option in Go: should we go with this PR or #115?

Is the description of this PR correct?

Make Sender so that it can't be implemented externally.

I thought we were concerned about making breaking changes by adding new public methods to the Sender. If that's the case, what if we instead wrote a test for each of our interfaces and use reflection to assert that only the desired methods are included? If someone adds a new method to an interface in the future, a unit test will fail to alert them that it would be a breaking change.

@keep94
Copy link
Copy Markdown
Contributor Author

keep94 commented Nov 7, 2022

@oppegard I may have been unclear in my description of this PR. It is fine if we or someone else adds methods to the Sender interface in the future. I anticipate we will need to do that sometime in the future. This PR will allow us to safely add methods to the Sender interface as non breaking changes going forward. What we don't want is for someone outside of our organization to write their own concrete type that implements Sender and then pass their custom concrete type to a function that accepts a Sender interface. If they are successful at doing that then as soon as we add any new methods to the Sender interface we would break that person's code so that it doesn't compile. That person would have to fix their code by adding implementations of any new method(s) we added to the Sender interface in their concrete type. This would be a breaking change on our end. To avoid this type of scenario in GO, it is idiomatic to add private methods to the interface to keep external parties from ever writing a successful implementation of it. A good example of this is the Type interface in the reflect package of Go.

As far as whether this PR or PR #115 is better I am indifferent. #115 would allow us to add examples for individual methods of sender, but #116 is a more friendly breaking change.

Copy link
Copy Markdown
Contributor

@oppegard oppegard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@keep94 keep94 merged commit e144509 into wavefrontHQ:master Nov 8, 2022
@keep94 keep94 deleted the sender-pinterface branch November 8, 2022 18:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants