I've got another debatable design question :)
I'm trying to put together a nice API, and one issue I'm struggling with
is the concept of an event handler with a single method. The interesting
issue is the choice and rationale behind one-method-interface vs. method
alias.
Example:
type Handler interface {
HandleEvent(event) error
}
vs.
type Handler func(event) error
If I expect more methods to be added later, then the first choice is the
obvious one. But if I'm (pretty) sure it will remain like this "forever",
then in the case of simpler handlers, the first one requires extra
boilerplate of defining a handler struct, whilst a simple method pass would
have done it. On the other hand if I choose the second, I can still simply
use somestruct.HandleEvent as the handler if it requires a more complex
handler.
My dilemma is pretty much present in the Go http package:
http://golang.org/pkg/net/http/#Handler vs.
http://golang.org/pkg/net/http/#HandlerFunc.
So what are your 2 cents? :)
Cheers,
Peter
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.