when building an interface in go the common example looks like:
type Notifier interface {
Notify()
}
The doc sees to say stuff like... add the 'er' version of the verb to the type name. Now since the method name and the interface name are similar having multiple methods in the definition would not makes sense.
I'm trying:
type Commander interface {
Command()
Notify()
}
it works in all the odd ways you'd expect but it seems wrong and there is nothing preventing me from doing this. I'm just not sure if I should be chaining the commands and what that might look like deeper in the code.
type Commander interface {
Command()
}
type Notifier interface {
Notify()
}
But the idea of calling my function:
DoStuff(c, n)
when a single param that implements both interfaces would make sense too.
That's perfectly fine, and it shows up in the standard library in a few places as well (e.g. http://golang.org/pkg/io/#ReadWriter).
Whether they should be in a single interface or two interfaces depends on if it makes sense or is ever useful to have a type implementing one but not the other.
One approach would be to do it like the ReadWriter
case in the standard library.
Define one interface:
type Commander interface {
Command()
}
and the other:
type Notifier interface {
Notify()
}
and then the type you want as a parameter:
type CommandNotifier interface {
Commander
Notifier
}
and finally define your function:
func DoStuff(cn CommandNotifier) {
// TODO - do stuff
}