Nuestro conocimiento compartido. Nuestro tesoro compartido. Wikipedia.
TreeWeb::Artículos::Golang::Breaking golang: static methods
Permalink: 19/02/2016

Breaking golang: static methods

Golang is a nice language, with a new concept of `method`. When your brain is working with typical object oriented designs, you could end up viewing the world with object oriented eyes, inheritance, polymorphism, object hierarchy, abstract methods... My brain is partially broken in that way so, sometimes, I get stucked forcing the language to a typical object oriented design.

In my opinion, Golang is not object oriented but data oriented. If we think carefully, all we do turn around data. The thing called `method` is a simply data resolution scope.
package main import "fmt" type Say func() string type Human struct { Name string SayHello Say } func main() { h := &Human{ Name: "John", SayHello: func() string { return "Hello, I am a human" }, } fmt.Println("Human says:", h.SayHello()) // Allow access to h h.SayHello = func() string { return "Hello, I am a human, My name is " + h.Name } fmt.Println("Human says:", h.SayHello()) }
We can also find an `interface` construction. Why? It is an interesting crazy merge between OO, duck typing and evilness. Why attributes cannot be defined inside an interface!

Warning: At this moment, I am being treated for objetorientedgitis and govilness.