• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

about MVC and connection

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use MVC to design my client,but which class should include database connection?at first I think Model class will do,because it implements searchFlight and bookFlight method.but it seems Controller class is more adaptive.so I'm confused.or make a connection class alone?
any answer is appreciated.
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Xin,
From Sun's design methodology blueprint describing MVC:

Model - The model represents enterprise data and the business rules that govern access to and updates of this data. Often the model serves as a software approximation to a real-world process, so simple real-world modeling techniques apply when defining the model.


Therefore, the model is the correct place to have your database connection.

Controller - The controller translates interactions with the view into actions to be performed by the model. In a stand-alone GUI client, user interactions could be button clicks or menu selections, whereas in a Web application, they appear as GET and POST HTTP requests. The actions performed by the model include activating business processes or changing the state of the model. Based on the user interactions and the outcome of the model actions, the controller responds by selecting an appropriate view.


So the Controller is used to pass the user interactions from the View to the class that is going to handle it. For the assignment, most of these interactions will be passed to the model, however they could go to other classes. E.g. if you have online help, then when the user clicks the help button, then the action is passed to the controller, which will then pass it to the classes that handle the online help.
Regards, Andrew
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Andrew Monkhouse:
Hi Xin,
From Sun's design methodology blueprint describing MVC:

So the Controller is used to pass the user interactions from the View to the class that is going to handle it. For the assignment, most of these interactions will be passed to the model, however they could go to other classes. E.g. if you have online help, then when the user clicks the help button, then the action is passed to the controller, which will then pass it to the classes that handle the online help.
Regards, Andrew


Andrew,
Is it ok for the model to generate events for the view listeners. For example in one my views (Results screen) i initialize the results table data to zero rows when the application starts up. But as soon as the user queries for flights by using the search screen the model updates the results data with the new results and generates a event for the 'Results screen' to update its table model.
Thanks for ur time.
-Poorna Lakki
 
Andrew Monkhouse
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Poorna,
Yes, this is desirable.
Normally what you have is one model. In the real world (not necessarily for this assignment) you may have multiple views for that model. Each view would normally send events to the model via it's own controller. If the model just "returned" data to the view via the controller, then the other view(s) will be out of sync.
The solution is the observer-observable design pattern.
The model is observable, and each view registers itself with the model as an observer. Whenever a controller sends an event to the model that modifies the current data set, the model will fire a changed event to each observer that registered with it.
There were some recent posts in this forum discussing limitations of the Observer interface & Observable class provided by Sun. They also discuss the whole MVC pattern fairly thoroughly. Try looking at MVC topic for more information.
Regards, Andrew
 
xin dong
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your answers ,I ve understand how to arrange it.
 
Poorna Lakki
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Andrew Monkhouse:
Hi Poorna,
Yes, this is desirable.
Normally what you have is one model. In the real world (not necessarily for this assignment) you may have multiple views for that model. Each view would normally send events to the model via it's own controller. If the model just "returned" data to the view via the controller, then the other view(s) will be out of sync.
The solution is the observer-observable design pattern.
The model is observable, and each view registers itself with the model as an observer. Whenever a controller sends an event to the model that modifies the current data set, the model will fire a changed event to each observer that registered with it.
There were some recent posts in this forum discussing limitations of the Observer interface & Observable class provided by Sun. They also discuss the whole MVC pattern fairly thoroughly. Try looking at MVC topic for more information.
Regards, Andrew


Andrew,
Actually that post was the basis of my design. I got confused by ur first post where u explained everything in the MVC model except for the interaction between the model and the view. But it is clear now. Now i feel a lot confident about my design.
Thanks for ur comments.
-Poorna Lakki
 
A feeble attempt to tell you about our stuff that makes us money
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic