Re:Half a decade with Go
by ansible on Tuesday November 11, 2014 @03:50AM
(#8588924)
(Incidentally, though I moved past my then really poor understanding of Go interfaces, I wasn't able to apply the respondent's answer or my new general knowledge to achieve the abstraction I was looking for, and settled for just grinding out the same code for the dozen entities/endpoints it applied to.)
I definitely can't deny that using interfaces instead of regular OO classes takes some getting used to.
Though I don't understand why you had to grind out duplicate code for all the entities / endpoints though. I hacked up things a bit to get it to run on the playground, but as Jesse McNelis wrote, just passing the pointer to foo worked for the code you wrote.
Re:Half a decade with Go
by ansible on Tuesday November 11, 2014 @04:15AM
(#8589000)
That stuff is from the bson Mongo package. I didn't want to pull it into this example, so that it could run on the playground. I replaced dots with underscores in that case.
I definitely can't deny that using interfaces instead of regular OO classes takes some getting used to.
Though I don't understand why you had to grind out duplicate code for all the entities / endpoints though. I hacked up things a bit to get it to run on the playground, but as Jesse McNelis wrote, just passing the pointer to foo worked for the code you wrote.
http://play.golang.org/p/jNpK5CRBfv