4 ms·
Your example looks good as well. Opening gives more flexibility with how the code can be structured, say that you have two interfaces: type I interface {
by wowoc 10y ago
Your example looks good as well. Opening gives more flexibility with how the code can be structured, say that you have two interfaces:
type I interface {
A()
}
type J interface {
B()
}
And you have two structs that implement them, you can then group methods from the same interface together:
type X struct{}
type Y struct{}
func (x X) A() {}
func (y Y) A() {}
func (x X) B() {}
func (y Y) B() {}
I've seen that used in the Golang codebase, and sometimes it does seem useful.