I am wondering from best practice point of view whether it is better to use interface or first-class function, especially considering that Go encourages the use of small interfaces. Here is an example:
type SomethingDoer interface{
DoSomething(data Data)
}
func PerformWork(doer SomethingDoer){
//...
}
Or
type SomethingDoer func(Data)
func PerformWork(doer SomethingDoer){
//...
}
Is there some sort of a guideline when to use one vs the other? They seem like redundant features to me.
Thanks
Henry
Thanks for the replies. In terms of future extensibility, is it safe to say that interface is superior to first-class functions?
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't think so. A http.Handler usually has a ton of state, so a struct's method is handier than a closure.
And take a look at http.HandlerFunc!