File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Opening the main application window & MVC

 
Chris Zaremba
Ranch Hand
Posts: 54
Eclipse IDE Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen lots of examples and opinions on how to implement MVC but I've decide to use an implementation described here Modified MVC. Basically the controller sits between the model and view and the later two do not communicate directly with each other. So my constructor looks something like this



In addition to this my public void main(String[] args) method is in launcher class that deals with the command line arguments and this will launch the main window. What would be the best way to open the main window? Should the launcher creater the model, view and finally the controller instances? This couples the launcher class to each of the three MVC components. If the application was expanded and more windows were added this would result in each parent window knowing about all three child window components. This doesn't seem right to me. The only way I can see to stop this is to have a fourth class that create the MVC components and the launcher only calls this but I've not really seen this in any examples though. Andrews book has the main method in the view which makes that component the one that's in charge which is not inline with the implmentation I'm going for.
 
Roel De Nijs
Sheriff
Posts: 9180
77
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

I simply evaluated the command line arguments in my executable main class and then simply called something like new MainWindow(args);. The constructor of the MainWindow will perform the necessary initializations.

Kind regards,
Roel
 
Chris Zaremba
Ranch Hand
Posts: 54
Eclipse IDE Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

Would I be right in saying that MainWindow is the view part of the MVC? Although many example I've seen do it that way, I was under the impression that it's the controller that should be running the show.
 
Roel De Nijs
Sheriff
Posts: 9180
77
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My MainWindow is indeed the V. I have a controller (C) who communicates with the business service (M). C tries to get data from M and passes it to V and V renders it so the user can see the results of his search
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Chris!

Basically the controller sits between the model and view and the later two do not communicate directly with each other.


Well, that's how things work in regular MVC...

What would be the best way to open the main window?


Well champ, I myself didn't have any class called Controller or something because in Swing ActionListeners can be faced as controllers. So, given the command line argument, I open the proper configuration dialog. Then, based on the user's input, I instantiate the MainWindow inside the ActionListener that listens to the OK button of the launch dialog.

And finally, please take a look here. I think it might be helpful!
 
Chris Zaremba
Ranch Hand
Posts: 54
Eclipse IDE Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks chaps. I've decided to go with a normal MVC pattern where there the model does have a reference to the view and have stuck with the Model, View and Controller names. Now I've got my head around it, it actually makes things quite simple. The start up dialogue will come later but for now I have do records displaying and the search working so I'm a happy man
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic