Hello.
Would it prove too difficult to add an alternate style of code generation besides the current extension model to M4M? The current model is based on extension, which isn’t IMO really extension, but composition, as shown below.
public class MyComponent extends JPanel
{
private JComponent jComponent1;
private JComponent jComponent2;
public MyComponent() { initComponents(); }
private void initComponents()
{
// Initialize the layout/components and add to this
}
}
An alternative to this could be the ‘builder’ or ‘wrapper’ (or whatever =) pattern as shown below.
public class MyComponent
{
private JPanel jPanel;
private JComponent jComponent1;
private JComponent jComponent2;
public MyComponent() { initComponents(); }
private void initComponents()
{
// Initialize the panel and other components, add layout and components to panel
}
public JPanel getInstance() { return jPanel; }
// ...
}
This would have the added benefit of not only omitting the inheritance misuse, but also add the possibility for the wrapper class to extend another class if need be as well as providing an extra level of abstraction on top of the actual component. This would allow for example us to place internationalization/reinitialization code outside of the component.
It is easy enough to transform currently generated code to this, but then consequent changes to the design invalidate it.
Just a thought.