• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC question

 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I've been thinking in the MVC patern and I think ther is something that's missing me.
As far as I can see this patern concerning the assignment, the model will have a array of Objects[][] to be filled with the data from the table. Only two methods here, the getData and setData. The View will be the GUI and the controller will have all the methods to make the reservation, search the database, and will also be responsable for filling the array in the Model.
Am I right? I'm with this, and each post that I read concerning this makes me more confused.
Thanks,
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds pretty good to me.
Mark
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mark.
Thanks for your repply.
I've been out due to some problems, but here I am again. One last question. In the MVC, the View uses the controller to register the actions. When a action is made, the Controller informs the Model that after that updates the View.
This means that the view don't know anything on the controller. The controller knows everything of the Model, and the Model must know a bit of the View (knows the method that updates the GUI)!
Is this correct?
My idea is to create a class that implements the ActionListener interface as a controller. The Model has the methods to make the Search, Reservation, etc... the idea of the Model could be a be a DatabaseFacade. After any method in the DatabaseFacade has been processed, we can call a method in the GUI like "dataChanged(Object[][]) that updates the JTable.
Comments please.
Thanks,
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My idea is to create a class that implements the ActionListener interface as a controller.

I wouldn't do that, what if you want to catch a Keyboard action from the GUI, then your controller can't do that, the Listeners need to be Anonymous Inner classes inside the controller.
Also the Model should not know about the view either. Usually the model will change based on a call from the controller to the DataAccess class, and therefore knows that it is having the Model change, so it can send the model to the view for the model.
Mark
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again.
I've implemented my MVC as follows:

The main window implements this interface and also the ChangeListener.
The controller implements ActionListener for the buttons and ListSelectionListener for the JTable, and all the actions in the main window have a name defined using "setActionCommand". The controller, when receives a action checks the event.getActionCommand and then calls the methods defined in the FBNControllerInterface for the main window and sends the commands to the model.
After a command is executed, the model fires the ChangeListener and updates the view.
Everything is working OK, but now I need is your comments on this MVC implementation. I'm counting on you guys .
Thanks,
Miguel
P.S. - I'm about to go on weekend , and the weekend is for fun , so I will only get back here on Sunday evening.
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
No coments? May I assume that this is OK?
Please revert.
Miguel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic