Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubts on MVC

 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement MVC pattern for my GUI.
I defined the following objects:
Controller .
DataModel - this represents of logical model of the data and recieves the data from the Database.
The DataView - view provides all GUI-staff (buttons, text-fields, Tables etc.)
I am trying to design MVC using the following structure:
View <-----> Controller <------> Model

That's mean I don't want to have any direct relation between View and Model. As I understand MVC correctly I can use this structure. Am I right?
I defined two listeners. One shows that Model was changed. And the second shows that View was changed.
I implemented these two listeners in my Controller. My Controller knows about Model and View (has instances). And Model doesn't communicate with View directly and vice versa. The communication occurs only with the help of Controller.
If the user presses some button (e.g. "Find"), View notifies the Controller that the state was changed. Controller says it to the Model (call some methods from Model) and the Model prepares data (e.g. call the Database) for find. After the data is prepared Model notifies the Controller. And Controller says it to the View (give the prepared Data from Model to View) and the View shows this Data in the table.


Do I understand and implement the MVC pattern correctly?
Thanks a lot for your help!
Olena
[ March 30, 2005: Message edited by: Olena Golub ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Olena Golub:
I am trying to design MVC using the following structure:
View <-----> Controller <------> Model

That's mean I don't want to have any direct relation between View and Model. As I understand MVC correctly I can use this structure. Am I right?


Not, that's definitely *not* MVC. It looks much more like Model View Presenter, which isn't bad either (and which often gets confused with MVC). You might want to google for it.
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ilja,
Thanks for your Answer
As I know Model View Presenter is the derivation of MVC.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MVC allows the view to depend on the model but not the other way around. A view might implement an interface required by the model and then register to be notified of data changes. The model could publish a data changed message any time something changes. You can either include the changed data on the message or require the view to turn around and ask for the changed data.
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reimplemented it.
My controller and View know about Model, but model doesn't know anything about Controller and View.



Is it correct interpretation of MVC?
Regards,
Olena
[ March 30, 2005: Message edited by: Olena Golub ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some might quibble with who glues things together - you have the window connecting the view, model and controller while we might make a special application assembler or have the controller do it. That's not a big issue, and it's going a good direction.

This gets more interesting in larger systems. You have an interface that the model talks to and the view implements so model and view both depend on the interface. It would be good to somehow show that the model owns the interface, most likely by putting them together in a package. Then the view package clearly depends on the model package. You might substitute the word "component" for package, depending on how you build and deploy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic