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 
at https://github.com/ChrisHines/talks/tree/master/non-orthogonal-choices-in-go.

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 
> <javascript:>> wrote:
>> On Wed, Oct 12, 2016 at 11:05 PM,  <sh...@tigera.io <javascript:>> wrote:
>> >  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.
>> https://golang.org/pkg/net/http/#HandlerFunc

You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to