If you want to dig into this topic more. I gave a presentation on this
topic at my local Go meetup earlier this year.
The slides from my talk are
Some of the code examples will not run on the public go-talks app. The
source material is
If you just want my conclusion:
*Informed choices for dynamic behavior:*
Use interface values when:
- Well known interfaces already exist, e.g. io.Reader
- More than one behavior required
- Typically stateful
- Implementations non-trivial
Use function values when:
- Only one behavior
- Typically stateless
- In-line implementations typical
Based on these guidelines and the outline of your code you've provided, I
agree with Ian that a function value is the best fit for your case.
On Wednesday, October 12, 2016 at 2:33:47 PM UTC-4, Shaun Crampton wrote:
> Thanks for the tips.
> On Wed, Oct 12, 2016 at 2:11 PM Jesse McNelis <jes...@jessta.id.au
>> > Seems like a function
>> > pointer is more universal (I don't even need an object to be a
>> receiver) but
>> > maybe an interface is more idiomatic?
>> An interesting pattern from the http pkg is that a function type can
>> also implement an interface.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.