• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to cleanly seperate Model/View/Controller ?

 
Krishna Varma Adluru
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers !!!
Can someone explain me how to cleanly seperate GUI into Model/View/Controller .. I was able to seperate into Model/ViewController .. But, I could not seperate View and Controller...I have read through several posts at here, but,could not get it ....

Here is how I did it:
Here is My ViewController:
public class DataViewController implements Observer{
public DataViewController(DataAccess dataAccess, DataModel dataModel) {
}
public void update(Observable obs, Object obj) {
}
public void actionPerformed(ActionEvent ae) {
String criteriaString = buildCriteria(HashMap of selected values in ComboBox);
DataInfo[] data = dataAccess.criteriaFind(criteriaString);
dataModel.setTableModel(data);
Vector dataVector = dataModel.getDataVector();
Vector columnNames = dataModel.getColumnNames();
tableModel.setDataVector(dataVector, columnNames);
}

}

Here is My TableModel:

public class DataModel extends Observable {
DefaultTableModel tableModel = null;
//Series of Setters and Getters
}

Can I know How to seperate View and Controller ?... Also,please let me know if there are any other Bad design choices I made !!! (For example, my DataModel did not extend
AbstractDataModel/DefaultDataModel ... Infact, it is a composition of DefaultDataModel) ...

Thanks Guys,
Regards,
Krishna Varma Adluru
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your design, I am not sure why you have to implement Observer and Observable. You are not doing any thing in the update method.
As long as you've a seperate class/source file for the GUI component (JPanel/JFrame) and handle the events in the controllers(seperate class/source file), I think you are safe. You can keep the table model in the controller and update it like you are doing in actionPerformed() method.
 
Krishna Varma Adluru
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sai Prasad:
In your design, I am not sure why you have to implement Observer and Observable. ..

If there are 2 or more clients connected to DataServer, I am planning to update all the Clients, if any one client makes a modification to DataModel(like making a reservation)

You are not doing any thing in the update method..

Update method is still unfinished. I am implementing Observer and Observable

Regards,
Krishna
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the spec, it is not required to update other gui clients when data is changed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic