Implementing MVC pattern in SWT application
- by Pradeep Simha
I am developing an SWT application (it's basically an Eclipse plugin, so I need to use SWT). Currently my design is as follows:
Model: In model, I have POJOs which represents the actual fields in views.
View: It is a dumb layer, it contains just UI and contains no logic (not even event handlers)
Controller: It acts as a mediator b/w those two layers. Also it is responsible for creating view layer, handling events etc.
Basically I have created all of the controls in view as a static like this public static Button btnLogin and in controller I have a code like this:
public void createLoginView(Composite comp) {
LoginFormView.createView(comp); //This createView method is in view layer ie LoginFormView
LoginFormView.btnLogin.addSelectionListener(new SelectionListener() {
//Code goes here
});
}
Similalrly I have done for other views and controls. So that in main class and other classes I am calling just createLoginView of controller. I am doing similar thing for other views.
So my question, is what I am doing is correct? Is this design good? Or I should have followed any other approach. Since I am new to SWT and Eclipse plugin development (basically I am Java EE developer having 4+ years of exp). Any tips/pointers would be appreciated.