• 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

Opening the main application window & MVC

 
Ranch Hand
Posts: 54
Eclipse IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic