Implementing MVC pattern in SWT application

Posted by Pradeep Simha on Programmers See other posts from Programmers or by Pradeep Simha
Published on 2013-07-02T06:07:53Z Indexed on 2013/07/02 11:14 UTC
Read the original article Hit count: 381

Filed under:
|
|

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.

© Programmers or respective owner

Related posts about java

Related posts about design-patterns