I am trying to understand how the UI components should be wired in Java. As far as regular "server" classes are concerned, I am trying to use interfaces and inject everything using Spring. In case of the UI, should similar approach be used?
To be more precise, let's consider the following:
class Panel1 extends JPanel{
public Panel1(Service service, DBConnector db);
}
class Panel2 extends JPanel{
public Panel1(Delegate delegate, Executor exec);
}
class MainFrame{
public MainFrame(Service service, DBConnector db, Delegate delegate, Executor exec){
Panel1 p = new Panel1(service, db);
Panel1 p = new Panel1(delegate, exec);
}
}
vs
class MainFrame{
public MainFrame(Panel1 panel1, Panel2 panel2){
}
}
I just wanted to get a general feeling what is more appropriate in the UI world, if it at all differs from the regular classes (possibly with the fact that there could be many panels involved in the main frame)