Let's say I have a struct implementing an interface like below:
type IFace interface {
Method1()
Method2()
Method3()
}
type Face struct {
Prop1 string
Prop2 int
}
// IFace implementation here...
Now if I have method that accepts IFace
is it better to design it to accept a pointer to that interface of value?
- Accept pointer:
func DummyMethod(f *IFace) {
(*f).Method1()
}
- By value:
func DummyMethod(f IFace){
f.Method1()
}
My first guess is since these are structs, probably it's better to pass by value? Or is there a rule of thumb considering the size and nature of the struct when to start passing a pointer?
Also, when we are adding methods to a struct is it better to pass a pointer to the struct or it's value?