3 ms·
The author here should be leveraging Go interfaces and they wouldn't lose type safety. This assumes the structs themselves know how to draw. This is usually (n
by lobster_johnson 12y ago
The author here should be leveraging Go interfaces and they wouldn't lose type safety.
This assumes the structs themselves know how to draw. This is usually (not always) an antipattern, because it conflates data with behaviour.
I should be able to swap out the drawing implementation without having to change the data. For example, given a circle (cx, cy, radius) I should be able to draw it using SVG or OpenGL.
The enum way is not necessarily "unidiomatic Go". Even if you have something that turns data structs into "strategy" objects that know how to render, you need a matching statement, or you need to build something like a "map[Type]Drawer", which is in my opinion less elegant.
- jblow 12y agoYeah, umm, especially in high-end games, the idea of every object "knowing how to draw itself", in the stereotypical OO way, is completely absurd.