I am new to GUI design and am struggling a little to decide whether my intended use of inheritance is acceptable (I am familiar with the general concept of favouring composition).
For example, if I have a GUI that will feature 3 JToolBars (two toolbars at the top and a status bar at the bottom) as I see it I have 2 obvious options:
- Simply instantiate 3 JToolBars, add various components to them (buttons, etc), then add these to the parent panel. The code to do all this would probably be in the parent panel (i.e. a number of private methods).
- Create 3 new classes - UpperToolBar, LowerToolBar, StatusBar. Each would sub-class JToolBar and contain the necessary code to 'build themselves' (probably in private methods called from the constructor in each case).
My immediate preference is the 2nd option, simply in terms of encapsulation, modularity, etc. However, it sort of seems wrong to be sub-classing JToolBar but not actually adding any functionality? Is this acceptable or is there a better alternative.