I know I am not supposed to think about virtual functions when programming in Go. :> However, recently I noticed that there is a "code reuse via dynamic dispatch" pattern lurking in some of my projects anyway, and so I took some time to extract it into a demo project to help myself re-execute the pattern should the need arise again. I also performed a simple benchmark with the demo to get some idea of the performance overhead of this pattern. I thought maybe I can share the demo project here:
https://github.com/maverickwoo/go-vtable-demo
Cheers!
评论:
ar3s3ru:
I don't get the meaning of this.
We already have dynamic dispatching in Go, through embedding and interface mechanisms.Also, your code seems not to follow the best practices (a.k.a. "idiomatic Go"), so I'd suggest you to learn those!
