Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How to cleanly seperate Model/View/Controller ?

 
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
 
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.
 
I knew that guy would be trouble! Thanks tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic