I’m building my own Canvas-style JPanel subclass which will draw a graph of nodes and arcs.
As part of this application I am delegating the drawing of the nodes to a sprite class Node, i.e
Class Visualiser extends JPanel {
...
paintComponent(Graphics g) {
...
node.draw(g);
...
}
}
But I also have a class Node for a data structure. I’m not concerned about the nomenclature, I can call one NodeSprite to avoid conflicts, etc…
What I am wondering is whether to merge the data structure and the sprite class into one, as logically they both describe the same real-world thing, or if doing this would have any negative side effects such as performance, or general bad design.
Any suggestions?
If a
NodeSpritehas behavior other than knowing how to print itself, it would violate the single responsibility principle. If all it knows how to do is draw, I would keep it that way and consider renaming itNodeSpritePrinteror something similar.