• Post Reply Bookmark Topic Watch Topic
  • New Topic

MVC pattern: view-controller relation in practice

 
Emanuele Mazzante
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

this is my first attempt to create an application following the MVC pattern. My frame is composed of a JTable with some JComboBox and classic next/previous buttons to page the table. The table shows data of current accounts of the members of a family.

My problem is figuring out how the controller interacts with the view, for example to enable / disable buttons or reset and reload the data in the comboboxes. In the view class all the graphical components are private instance variables. What is the best approach to ensure that the controller can act on them?

I need to create in the view public methods to act on each component like getSelectedItemAccountCombo, getSelectedItemYearsCombo, getSelectedItemMonthCombo, populateAccountCombo (ArrayList <String> list), setNextButton (boolean b) ... and so on (I think that the methods would be many ...)
This approach does not convince me because I think that the class is fouled by procedures that should be in the controller class.

Thank you for your help.
 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you found any MVC tutorials?
 
Emanuele Mazzante
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell and thanks for your interest.

I began to study the pattern with the Head first design pattern book and then trying to develop the program by following those patterns. Then I found other tutorials on the internet but sometimes the examples seem much different than the book.
For example, in this article the author recommends that you do not have relationships between the view and the model while in the book the view and the model have references to each other (like the observer pattern):
http://alvinalexander.com/uml/uml-model-view-controller-mvc-diagram

In the book the user's actions on the view call the methods of the controller unlike other tutorials where the controller creates the various Listener objects and passes them to the view (I understand that this may be a subtle difference).

Finally I saw that the rule of programming to an interface is rarely used.
I know that all tutorials and examples works but I'm trying to understand what is the recommended way for a good design.

Thank you for your help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!