I am looking at the example code at: https://golang.org/pkg/net/rpc/
type Arith int
func (t *Arith) Multiply(args *Args, reply *int) error {
*reply = args.A * args.B
return nil
}
From an OOP perspective, Multiply
seems like a static method which doesn't access any data in Arith
class; as the variable t
is not used. Does it mean that int
in type Arith int
does not have any significance?
This doesn't have anything to do with OOP, it's simply that the rpc package's convention works by exporting methods from an "object" (with object here meaning any value with a non-empty method set)
The int
is significant as the type of Arith
, but it's not significant in this particular example, since the receiver is never referenced in the methods.
So yes, this example is kind of like a static class, but try not to map Java OOP ideas to Go, because Go is very different, as there are no "classes" or inheritance.