good
good copied to clipboard
Multisignatures
Let's say we have this struct:
type SomeStore struct {
b int
c string
d float64
}
User should be able to define functions like:
func Store(n int) *SomeStore {
return &SomeStore{b: n}
}
func Store(c string) *SomeStore {
return &SomeStore{c: c}
}
func Store(d float64) *SomeStore {
return &SomeStore{d: d}
}
And methods:
func (s *SomeStore) Set(n int) {
s.b = n
}
func (s *SomeStore) Set(c string) {
s.c = c
}
func (s *SomeStore) Set(d float64) {
s.d = d
}
And more on methods:
func (a *A) Set(anotherA *A) {
a.b = anotherA.b
a.c = anotherA.c
a.d = anotherA.d
}
func (a *A) Set(c string) {
a.Set(15<<2, c)
}
func (a *A) Set(c int, d string) {
a.b = c
a.c = d
}
I've used this in my Java days.
finally I found it is more convenience to have clear methods name
Multidispatch for the win!