Hello all,
I am golang beginner. And I have a problem with interfaces.
Here is the problem where I have one main package with has an Interface I. and multiple sub packages each implementing interface I. So I have a method which is exactly the same for all sub packages. Is there a way I can implement this method for I.
package main
type I interface {
F1()
GenericMethod() // Is there a way I can implement it on I since its the same in all packages?
}
package p1
type P1data struct {}
(x *P1data) F1()
(x *P1data) GenericMethod()
package p2
type P2data struct {}
(x *P2data) F1()
(x *P2data) GenericMethod()
under the main package.
for each data in sub packages do data.F1 and data.GenericMethod().
Now I don't want to implement GenericMethod for all packages. Since its the same.So can I implement GenericMethod on I (I know this is not possible). But how can do something like this?
-Thanks