Skip to content

Instantly share code, notes, and snippets.

@jrozner
Created April 14, 2020 23:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrozner/75ba8144c0bda8bb2e0429373b9e72fb to your computer and use it in GitHub Desktop.
Save jrozner/75ba8144c0bda8bb2e0429373b9e72fb to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
s1 := &FakeStruct1{}
runMethods(s1)
s2 := &FakeStruct2{}
runMethods(s2)
s3 := &FakeStruct3{}
runMethods(s3)
}
func runMethods(i SomeInterface) {
i.Method1()
i.Method2()
i.Method3()
i.Method4()
}
type SomeInterface interface {
Method1()
Method2()
Method3()
Method4()
}
type Nop struct{}
func (n *Nop) Method1() {}
func (n *Nop) Method2() {}
func (n *Nop) Method3() {}
func (n *Nop) Method4() {}
type FakeStruct1 struct {
Nop
}
func (f *FakeStruct1) Method1() {
fmt.Println("do something 1")
}
type FakeStruct2 struct {
Nop
}
func (f *FakeStruct1) Method2() {
fmt.Println("do something 2")
}
type FakeStruct3 struct {
Nop
}
func (f *FakeStruct3) Method3() {
fmt.Println("do something 3")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment