1 Attachment(s)
How complex is too complex for a single class?
I am creating a GUI that, as currently built, has a wonderful hierarchy of panels for different groups of components. I have all of these panels in their own classes. Every time I look at my collection of code files, I can't help but feel that I've horribly complicated matters and have gone way overboard in creating classes for panels, instead of, for example, building the entire frame's contents in a single class.
Attached is an image of my frame, with all of the panels bordered in red. I'm counting five panels.
Attachment 1645
My question to the forums: When should a panel be in its own class and when should it be built within the class building its parent? Should I have created this frame in two classes: the JFrame class and the JPanel class, or is it right to have a million classes for all the panels that are used?
I have spent hours searching the Google to find some consensus on how to handle container hierarchies, building strategies, using nested classes, subclassing, etc., for some idea of how I should be organizing the code for building this frame. Separate classes feel more modular, but it feels almost like semantics to build panels as individual units when they will only ever be used in a specific configuration? Subclassing feels misplaced, though it does lay out things nicely in Eclipse's outline panel. I'm dying for advice that actually sounds like it fits my situation!