• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubts on MVC

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I am trying to design the MVC part of my project.
I use following structure:
View <-----> Controller <------> Model

I have the following classes:
Controller .
DataModel - this represents of logical model of the data and recieves the data from the Database.
The MainWindow - view provides all GUI-staff (buttons, text-fields, Table).

After the user startes the programm as remote-Client or local client and selectes the
necessary information(database location, or port, or IP) this information will be passed to MainWindow.
And the MainWindow initializes the Controller.
And Controller initializes than the DataModel.
After the controller calles initialization method of the DataModel, model gets with the help of the ConnectionFactory
the instance of the DataAdaptor (local or remote). And all DataAdaptor methods will be called from the DataModel.


(it's only sketch-code)

It works in such a way:

The user enters the search criteria and then presses the "find" button. This calles the method findByCriteria in the controller.
The Controller calles the correcponding method in the DataModel and DataModel recieves the data from
the database (DataAdaptor for local or DataAdaptorRemote for remote). And sents it to Controller. Controller creates the MyTableModel
and sents it to MainWindow.

My questions are.
Do I correct implement the MVC pattern? Are the interaction correct?
Am I missing something?

Or is it correct to have a controller that has DataModel and View objects?
Thanks for you comments!
Regards,
Olena

[ March 28, 2005: Message edited by: Olena Golub ]
[ March 28, 2005: Message edited by: Olena Golub ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you have created is good and it is the basic besign of MVC.<br/>
avoid hardcoding the connections among the MODEL, VIEW and CONTROLLER.<br/>
Bring it outside of the code.
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kalyan kumarG:
what you have created is good and it is the basic besign of MVC.<br/>
avoid hardcoding the connections among the MODEL, VIEW and CONTROLLER.<br/>
Bring it outside of the code.



This is a good suggestion. I used the Observer pattern to allow any interested objects (such as the Views and Controller) to register their interest with the Model and be informed of changes to the Model. I also had the Controller build the Actions and provide a way for different Views to get references to those Action objects.
[ March 28, 2005: Message edited by: peter wooster ]
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your comments.

But I am still confused. Do I need to implements this Observer pattern?
Do I recieve a minus points implements in a way that I described?

I will try to implements this with observer but I am not sure if I can this. I am not very familiar with this pattern

regards,
Olena
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Olena,

do you have the design patterns book Head First Design Patterns?

I love each pattern described in this fantastic book, it's Head First .

Regards,
Darya
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Olena Golub:
Thanks for your comments.

But I am still confused. Do I need to implements this Observer pattern?
Do I recieve a minus points implements in a way that I described?

I will try to implements this with observer but I am not sure if I can this. I am not very familiar with this pattern

regards,
Olena



The Observer pattern is very simple to implement, and you already know how to use it. What you need is to add 2 methods to your model
- addModelListener
- removeModelListener
These manage a collection of interested listeners (observers). When something happens that is interesting you iterate through that collection and run the methods in an interface they implement.

Define an interface called ModelListener that contains methods such as
- dataAvailable
- stateChanged

In your View and Controller, implement ModelListener or use anonymous inner classes that do, and call the addModelListener method on the Model to register interest.

This sort of thing helps you get good marks for OO design.
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
thanks for your help!


In your View and Controller, implement ModelListener or use anonymous inner classes that do, and call the addModelListener method on the Model to register interest.



To implement the ModelListener in my View and than called addModelListener on the Model means that my View should have an
instance of the model. Am I right? But I don't want that view knows something about my model.
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about this?
If i have two Listeners: one for the model and one for the view.
If the view is changed, controller says it to the model. Model recieves the data and notifies the Controller. Controller than passes this data to view.

Only the change that i made: view will be initialized in the controller.
This means my View and Model don't know about controller.
Is is correct implementation of MVC and Observer? Or do I still need to implement only one Listener and implement it in view and controller?



[ March 28, 2005: Message edited by: Olena Golub ]
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I found out my second implementation that I showed above is not direct MVC but derivation that called Model-View-Presenter.
Can I use this pattern? What should I write about my GUI in my choises.txt that I use one kind of MVC or that I use MVP pattern and no words about MVC?
How do you think is my implementation correct?
Please comment it!
I am very thankful for your comments!
[ March 30, 2005: Message edited by: Olena Golub ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic