I am building a java desktop application where I am attempting to implement MVC. The GUI interface has multiple views (think pop-up windows) from the main view. Each view has its associated model that it receives updates from.

I am running into scenarios where two views need to access a particular data field from one model. This requires that one model "knows about" the another. What are my options to solve this?

The data field is a table that is populated in one of the views and is then subsequently accessed in the main splash view.

I have tried passing the second model into the first's constructor from the controller, however I feel this is sloppy. Should a model listen to another model (Observer pattern)? Perhaps my question is too subjective....

you should only need one model. that's one of the main ideas about mvc - a single model can have more than one view.
–
Ray TayekJan 29 '13 at 23:03

What is wrong with constructing one model using the data from another? Does not sound sloppy to me. As long as the view for the main window is updated with the new data it sounds like you are following the MVC pattern just fine.
–
mortalapemanJan 30 '13 at 0:35

Having thought about it, what you are concerned about can be fixed by the factory pattern or something similar. Instead of using the constructor of the main model, have a class dedicated to building the main model that can take an instance of the other model as a parameter. That will decouple your models from each other.
–
mortalapemanJan 30 '13 at 0:44

1 Answer
1

Single model and multiple views - I see no problem in your case. Have you tried to implement observer pattern? If not, try to write your classes according to class structure suggested by observer pattern. I think it will solve problem.